CropPath 开发者

API 参考

attachments

4 个操作

GET /v1/attachments/{sha256}

Download a blob

身份验证:cookie, bearer, oauth2 · OAuth2 作用域:attachment_read · getAttachment

Admins and auditors tenant-wide; an operator through envelopes of its facilities, and a tenant-owned upload (it has no facility) only when a certification, spray record or satellite check of a growing area of its tenant (or an unowned one) cites it. Visible when an envelope of the caller's tenant references the hash and its bytes were uploaded for that reference, or the caller's tenant uploaded it. The Content-Type is the stored media type. Not public: no /v1/public/ route serves blobs. The photo of a land-use right certificate (#250: a hash that a land certificate of a growing area of the caller's company names as its photo_sha256) holds the land user's personal data: it is served only to a caller that may read land certificates (the company's tenant admins and a platform admin acting for it) through a signed-in session, never to an auditor, an operator, an API token or an OAuth client, which get 404.

参数

名称位置类型说明
sha256
必填
pathstring

SHA-256 of the blob: exactly 64 lowercase hex characters (anything else is 400 before any lookup).

响应

状态码类型说明
200string
application/pdf, audio/wav, image/jpeg, image/png

The blob's bytes.

400Error
application/json

Malformed sha256 in the path, or a bad X-Request-Id.

401Error
application/json

No valid session, API token or legacy token.

403Error
application/json

The caller is known but refused: role not permitted or tenant not allowed (X-Tenant).

404Error
application/json

No blob this caller may see: never uploaded, referenced but not uploaded yet, owned by another tenant, or (for a facility-scoped operator) referenced only by envelopes outside its facilities or a tenant upload no growing-area record cites, all answer exactly alike. So does a land certificate's photo for a caller that may not read land certificates through a signed-in session.

405Error
application/json

The path exists but not for this method. Allow lists the methods it accepts.

500Error
application/json

Unexpected failure; the detail is only in the server log.

响应头

名称状态码类型说明
X-Request-Id200string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Content-Type-Options200string

Always nosniff.

Content-Disposition200string

Always attachment; filename="<sha256>.<wav|jpg|png|pdf>": never rendered in the app origin.

Content-Security-Policy200string

Always default-src 'none'; sandbox.

Cache-Control200string

private, no-cache.

X-Request-Id400string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id401string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id403string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id404string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id405string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

Allow405string

Comma-separated methods the path accepts.

X-Request-Id500string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

响应示例

响应 200 · application/pdf
%PDF-1.7 ... (binary PDF bytes)
响应 200 · audio/wav
RIFF....WAVEfmt  ... (binary PCM WAV bytes)
响应 200 · image/jpeg
(binary JPEG bytes, starting FF D8 FF)
响应 200 · image/png
(binary PNG bytes, starting 89 50 4E 47 0D 0A 1A 0A)
响应 400 · application/json · invalid_hash
{
  "error": "invalid hash",
  "code": "invalid_hash"
}
响应 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
响应 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
响应 403 · application/json · role_not_permitted
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
响应 403 · application/json · tenant_not_allowed
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
响应 404 · application/json
{
  "error": "not found: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
  "code": "not_found"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

PUT /v1/attachments/{sha256}

Upload a blob owned by the caller's tenant

身份验证:cookie, bearer, oauth2 · OAuth2 作用域:attachment_upload · uploadAttachment

For blobs no envelope references (a satellite-check image, a lab PDF). platform_admin and tenant_admin; the owner is the tenant the caller acts for (X-Tenant for a platform admin). The body must hash to sha256, be at most 1 MiB, have an allowlisted Content-Type (parameters ignored) and that type's signature. A blob the tenant already owns: 200 without reading the body. Audited (attachment.upload: the hash, media type and size, never the bytes).

参数

名称位置类型说明
sha256
必填
pathstring

SHA-256 of the blob: exactly 64 lowercase hex characters (anything else is 400 before any lookup).

请求体

string (必填)

媒体类型: application/pdf, audio/wav, image/jpeg, image/png

请求示例 · application/pdf
%PDF-1.7 ... (binary PDF bytes)
请求示例 · audio/wav
RIFF....WAVEfmt  ... (binary PCM WAV bytes)
请求示例 · image/jpeg
(binary JPEG bytes, starting FF D8 FF)
请求示例 · image/png
(binary PNG bytes, starting 89 50 4E 47 0D 0A 1A 0A)

响应

状态码类型说明
200AttachmentStored
application/json

The tenant already owns this blob; nothing changed.

201AttachmentStored
application/json

Stored and owned by the caller's tenant.

400Error
application/json

Malformed sha256 in the path, a missing or malformed Content-Length, or a bad X-Request-Id.

401Error
application/json

No valid session, API token or legacy token.

403Error
application/json

The caller is known but refused: role not permitted, tenant not allowed (X-Tenant), origin not allowed or CSRF token missing or invalid (cookie sessions on unsafe methods). SELF-2-4 (#193): also company read-only while the company is leaving CropPath or has left (its records can be read and exported, not changed).

405Error
application/json

The path exists but not for this method. Allow lists the methods it accepts.

413Error
application/json

The request body is over 1 MiB.

415Error
application/json

Media type outside the allowlist (audio/wav, image/jpeg, image/png, application/pdf) or not the one declared, or bytes that do not start with that type's signature.

422Error
application/json

The body does not hash to sha256; nothing is stored.

500Error
application/json

Unexpected failure; the detail is only in the server log.

响应头

名称状态码类型说明
X-Request-Id200string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id201string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id400string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id401string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id403string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id405string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

Allow405string

Comma-separated methods the path accepts.

X-Request-Id413string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id415string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id422string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id500string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

响应示例

响应 200 · application/json
{
  "sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
  "media_type": "audio/wav",
  "size": 115244
}
响应 201 · application/json
{
  "sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
  "media_type": "audio/wav",
  "size": 115244
}
响应 400 · application/json · invalid_hash
{
  "error": "invalid hash",
  "code": "invalid_hash"
}
响应 400 · application/json · bad_content_length
{
  "error": "bad content length",
  "code": "bad_content_length"
}
响应 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
响应 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
响应 403 · application/json · role_not_permitted
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
响应 403 · application/json · tenant_not_allowed
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
响应 403 · application/json · csrf_token_missing_or_invalid
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
响应 403 · application/json · origin_not_allowed
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
响应 403 · application/json · company_read_only
{
  "error": "company read-only: the company is leaving or has left CropPath; its records can be read and exported but not changed",
  "code": "company_read_only"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
响应 415 · application/json · unsupported_media_type
{
  "error": "unsupported media type",
  "code": "unsupported_media_type"
}
响应 415 · application/json · content_does_not_match_the_media_type
{
  "error": "content does not match the media type",
  "code": "content_does_not_match_the_media_type"
}
响应 422 · application/json
{
  "error": "hash mismatch",
  "code": "hash_mismatch"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/attachments/{sha256}/peaks

Waveform peaks of a WAV blob

身份验证:cookie, bearer, oauth2 · OAuth2 作用域:attachment_read · getAttachmentPeaks

Same visibility as the blob. PCM 8/16/24/32-bit WAV, any channel count. The frames are split into n buckets as evenly as integer division allows (one bucket per frame when there are fewer frames than n); each bucket is [min, max] over every sample of every channel, normalised to -1..1 of full scale and rounded to 4 decimals.

参数

名称位置类型说明
sha256
必填
pathstring

SHA-256 of the blob: exactly 64 lowercase hex characters (anything else is 400 before any lookup).

n
可选
queryinteger

Number of buckets, 1 to 4096 (default 560).

响应

状态码类型说明
200AttachmentPeaks
application/json

The peaks.

400Error
application/json

Malformed sha256 in the path, n not an integer from 1 to 4096, or a bad X-Request-Id.

401Error
application/json

No valid session, API token or legacy token.

403Error
application/json

The caller is known but refused: role not permitted or tenant not allowed (X-Tenant).

404Error
application/json

No blob this caller may see: never uploaded, referenced but not uploaded yet, owned by another tenant, or (for a facility-scoped operator) referenced only by envelopes outside its facilities or a tenant upload no growing-area record cites, all answer exactly alike.

405Error
application/json

The path exists but not for this method. Allow lists the methods it accepts.

415Error
application/json

The blob is not audio/wav, or not a PCM WAV the server can read.

500Error
application/json

Unexpected failure; the detail is only in the server log.

响应头

名称状态码类型说明
X-Request-Id200string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

Cache-Control200string

private, no-cache.

X-Request-Id400string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id401string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id403string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id404string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id405string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

Allow405string

Comma-separated methods the path accepts.

X-Request-Id415string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id500string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

响应示例

响应 200 · application/json
{
  "sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
  "n": 4,
  "channels": 1,
  "sample_rate": 48000,
  "frames": 57600,
  "duration_s": 1.2,
  "peaks": [
    [
      -0.5,
      0.5
    ],
    [
      -0.25,
      0.75
    ],
    [
      0,
      0
    ],
    [
      -1,
      0.9999
    ]
  ]
}
响应 400 · application/json · invalid_hash
{
  "error": "invalid hash",
  "code": "invalid_hash"
}
响应 400 · application/json · bad_n
{
  "error": "bad n",
  "code": "bad_n"
}
响应 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
响应 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
响应 403 · application/json · role_not_permitted
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
响应 403 · application/json · tenant_not_allowed
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
响应 404 · application/json
{
  "error": "not found: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
  "code": "not_found"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 415 · application/json · not_a_wav_attachment
{
  "error": "not a wav attachment",
  "code": "not_a_wav_attachment"
}
响应 415 · application/json · not_a_pcm_wav_attachment
{
  "error": "not a pcm wav attachment",
  "code": "not_a_pcm_wav_attachment"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

PUT /v1/devices/{id}/attachments/{sha256}

Upload the bytes of an attachment one of the device's envelopes references

身份验证:deviceMtls · uploadDeviceAttachment

For devices and gateways after the envelope was sent (the SDK's WAV upload, #24, targets this route). Accepted only when a stored envelope of device {id} lists sha256 as an attachment; any bytes that hash to it are the signed content. Over mTLS the client certificate CN must be the device or the active gateway the envelope names (403 otherwise, the ingest rule); over plain HTTP (development) the reference and the hash are the whole check. Content-Type (parameters ignored) must equal the declared mediaType and be allowlisted; the body must hash to sha256 and, when the envelope declares size, have that length; the bytes must carry the media type's signature. Already uploaded: 200 without reading the body. SELF-2-4 (#193): refused 403 company_read_only once the envelope's company is leaving CropPath or has left (storing the bytes would change its public fruit page). Never returns blob bytes. Not audited: the attachments row records the upload (see AUDIT_EXEMPT).

参数

名称位置类型说明
id
必填
pathstring

Device id of the envelope that references the blob.

sha256
必填
pathstring

SHA-256 of the blob: exactly 64 lowercase hex characters (anything else is 400 before any lookup).

请求体

string (必填)

媒体类型: application/pdf, audio/wav, image/jpeg, image/png

请求示例 · application/pdf
%PDF-1.7 ... (binary PDF bytes)
请求示例 · audio/wav
RIFF....WAVEfmt  ... (binary PCM WAV bytes)
请求示例 · image/jpeg
(binary JPEG bytes, starting FF D8 FF)
请求示例 · image/png
(binary PNG bytes, starting 89 50 4E 47 0D 0A 1A 0A)

响应

状态码类型说明
200AttachmentStored
application/json

Already uploaded for this reference; nothing changed.

201AttachmentStored
application/json

Stored.

400Error
application/json

Malformed sha256 in the path, a missing or malformed Content-Length, or a bad X-Request-Id.

403Error
application/json

Over mTLS, the client certificate is neither the device nor the gateway the envelope names (peer_mismatch). SELF-2-4 (#193): or the envelope's company is leaving CropPath or has left (company_read_only): nothing is stored.

404Error
application/json

No stored envelope of this device references the hash.

405Error
application/json

The path exists but not for this method. Allow lists the methods it accepts.

413Error
application/json

The request body is over 1 MiB.

415Error
application/json

Media type outside the allowlist (audio/wav, image/jpeg, image/png, application/pdf) or not the one declared, or bytes that do not start with that type's signature.

422Error
application/json

The body does not hash to sha256, or its length differs from the declared size; nothing is stored.

500Error
application/json

Unexpected failure; the detail is only in the server log.

响应头

名称状态码类型说明
X-Request-Id200string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id201string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id400string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id403string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id404string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id405string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

Allow405string

Comma-separated methods the path accepts.

X-Request-Id413string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id415string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id422string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id500string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

响应示例

响应 200 · application/json
{
  "sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
  "media_type": "audio/wav",
  "size": 115244
}
响应 201 · application/json
{
  "sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
  "media_type": "audio/wav",
  "size": 115244
}
响应 400 · application/json · invalid_hash
{
  "error": "invalid hash",
  "code": "invalid_hash"
}
响应 400 · application/json · bad_content_length
{
  "error": "bad content length",
  "code": "bad_content_length"
}
响应 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
响应 403 · application/json · peer_mismatch
{
  "error": "peer mismatch",
  "code": "peer_mismatch"
}
响应 403 · application/json · company_read_only
{
  "error": "company read-only: the company is leaving or has left CropPath; its records can be read and exported but not changed",
  "code": "company_read_only"
}
响应 404 · application/json
{
  "error": "not found: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
  "code": "not_found"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
响应 415 · application/json · unsupported_media_type
{
  "error": "unsupported media type",
  "code": "unsupported_media_type"
}
响应 415 · application/json · content_does_not_match_the_media_type
{
  "error": "content does not match the media type",
  "code": "content_does_not_match_the_media_type"
}
响应 422 · application/json · hash_mismatch
{
  "error": "hash mismatch",
  "code": "hash_mismatch"
}
响应 422 · application/json · size_mismatch
{
  "error": "size mismatch",
  "code": "size_mismatch"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}