# fileuploader

Source: https://zotonic.com/docs/2243/fileuploader

URI: https://zotonic.com/id/2243

Language: en



Model to start uploads, upload a block and delete uploads.

Topics
------

`model/fileuploader/post/new` starts a new fileupload.

The posted message must include the filename and the file size:

```javascript
{
    filename: "test.jpg",
    size: 1000
}
```

Clients can optionally send `digest`, the lowercase SHA-256 hash of the file. Before starting an uploader, the model checks for an accessible CAFS original. On a match it returns `is_complete: true` and `media_upload_token`, without an upload URL or upload process. Submit `{media_upload_token: Token}` as the form field value instead of a fileuploader reference. The bundled worker does this automatically. The token has the same permissions and expiry as `m_media`'s `/upload_check` API. On a miss the normal upload starts.

The upload URL and current status is returned for a normal upload:

```json
{
    "result": {
        "filename": "test.jpg",
        "is_complete": false,
        "missing": [
            {
                "size": 1000,
                "start": 0
            }
        ],
        "name": "WZkhXoaMwrK2StUHmdpp",
        "received": 0,
        "size": 10,
        "upload_url": "https://zotonic.test:8443/fileuploader/upload/WZkhXoaMwrK2StUHmdpp"
    },
    "status": "ok"
}
```

Status `"error"` is returned if the name is unknown or any error occured.

`model/fileuploader/post/delete/+name` delete a fileupload.

`model/fileuploader/post/upload/+name/+offset` upload data to a fileupload.

The offset must be an integer and the message payload must be binary data.

`model/fileuploader/get/status/+name` fetch the current fileupload status.

Available Model API Paths
-------------------------

| Method | Path pattern            | Description                                                                      |
| ------ | ----------------------- | -------------------------------------------------------------------------------- |
| `get`  | `/status/+name/...`     | Return sanitized upload status for `+name`: filename, total size, received bytes, completion flag, missing byte ranges, and absolute upload URL. |
| `post` | `/new`                  | Start or resume upload `name` for payload `filename` + `size` after media-insert ACL check, then return sanitized upload status metadata. No further lookups. |
| `post` | `/delete/+name`         | Stop and remove the upload worker/session identified by `+name` via `z_fileuploader:stop/1`. No further lookups. |
| `post` | `/upload/+name/+offset` | Append a binary chunk to upload `+name` at byte offset `+offset` and return updated sanitized upload status (including remaining ranges). No further lookups. |

`/+name` marks a variable path segment. A trailing `/...` means extra path segments are accepted for further lookups.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/2243?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/2243?language=en>)
