BUD06 - Upload requirements

This commit is contained in:
Quentin
2024-09-10 10:23:10 +02:00
parent 41cb9c9ef1
commit 4570963648
2 changed files with 57 additions and 1 deletions

View File

@@ -16,9 +16,10 @@ Blossom Servers expose four endpoints for managing blobs
- `GET /<sha256>` (optional file `.ext`) [BUD-01](./buds/01.md#get-sha256---get-blob)
- `HEAD /<sha256>` (optional file `.ext`) [BUD-01](./buds/01.md#head-sha256---has-blob)
- `PUT /upload` [BUD-2](./buds/02.md#put-upload---upload-blob)
- `PUT /upload` [BUD-02](./buds/02.md#put-upload---upload-blob)
- `Authentication`: Signed [nostr event](./buds/02.md#upload-authorization-required)
- Return a blob descriptor
- `HEAD /upload` [BUD-06](./buds/06.md#head-upload---upload-requirements)
- `GET /list/<pubkey>` [BUD-02](./buds/02.md#get-listpubkey---list-blobs)
- Returns an array of blob descriptors
- `Authentication` _(optional)_: Signed [nostr event](./buds/02.md#list-authorization-optional)

55
buds/06.md Normal file
View File

@@ -0,0 +1,55 @@
BUD-06
======
Upload requirements
---------------
`draft` `optional`
Defines how clients can verify if the upload can be completed before sending the blob to the server. This mechanism helps prevent unnecessary traffic to other endpoints by rejecting files based on their hash, size, MIME type or other server-specific requirements.
## HEAD /upload - Upload requirements
The `HEAD /upload` endpoint `MUST` use the `Content-Digest`, `X-Content-Type` and `X-Content-Length` headers sent by client to get the SHA-256 hash, MIME type and size of the blob that will be uploaded, returning a HTTP status code and a custom header `X-Upload-Message` to indicate some human readable message about the upload requirements.
### Headers
- `Content-Digest`: A string formatted as `sha-256=:<base64digest>:`, where `<base64digest>` is the base64-encoded SHA-256 hash of the blob.
- `X-Content-Length`: An integer that represents the blob size in bytes.
- `X-Content-Type`: A string that specifies the fblobile's MIME type, like `application/pdf` or `image/png`.
- `X-Upload-Message`: A human readable message that explains the reason why the upload cannot proceed.
### Examples
Example request from the client:
```http
X-Content-Type: application/pdf
X-Content-Length: 184292
Content-Digest: SHA-256=:88a74d0b866c8ba79251a11fe5ac807839226870e77355f02eaf68b156522576:
```
Example response from the server if the upload can be done:
```http
HTTP/1.1 200 OK
```
If the upload cannot proceed, the server `MUST` return an appropriate HTTP status code and a custom header `X-Upload-Message` with a human readable error message.
Some examples of error messages:
```http
HTTP/1.1 400 Bad Request
X-Upload-Message: Invalid Content-Digest header format. Expected format: sha-256=:<hash>:
```
```http
HTTP/1.1 413 Content Too Large
X-Upload-Message: File too large. Max allowed size is 100MB
```
```http
HTTP/1.1 415 Unsupported Media Type
X-Upload-Message: Unsupported file type.
```