Page History
...
Code Block | ||||
---|---|---|---|---|
| ||||
{"message":{"status":"complete","deleteCount":1}} |
Anchor | ||||
---|---|---|---|---|
|
Uploads a file to a file specific scope of a specific record. Files can only be uploaded to scopes that don't previously exist, or that already contain files. Put file uses multipart/form-data format to upload the file. Metadata associated with the file can also be specified as multipart/form-data fields.
Request
The put file PUT/POST multipart/form-data request URL requires the storageunit, record key and the scope where the file will be uploaded. The request multipart/form-data body requires at least a file field with the file reference. By default the version for the file will be set to 1 and the policy will be merge (same policies as the add action policies). To specify additional metadata for the file, add other multipart/form-data text fields to the request.
Code Block | ||||
---|---|---|---|---|
| ||||
PUT transaction/putFile/<storage-unit>/<key>/<scope> |
Headers:
- Content-type: multipart/form-data;boundary=BOUNDARY_TOKEN
Body:
- file: File type field where the file is specified. The filename will be used as the file identifier when requesting back the file.
- version: A version to chronologically identify the file transactions. If a file with the same filename already exists with a higher version, the filename will not be added.
- policy: The policy to use when adding a file:
- new: only adds the file doesn't exist in the scope.
- overwrite: if a file with the same name already exists, it overwrites all of it's previous metadata and updates the file.
- merge: if a file with the same name already exists, it adds any new metadata to the file metadata, overwrites existing metadata for that file.
- additional metadata: any other field in the request will be considered file metadata and saved as such. The field name can have the filename as a prefix, separated by a colon.
Response
If the file is uploaded correctly, a 200 response code and an OK message are returned.
Code Block | ||||
---|---|---|---|---|
| ||||
{"message":"OK"} |
Multiple File Upload
Using the same putFile request, multiple files can be uploaded at once to the same scope of a storage unit.
To upload multiple files, the multpart/form-data request accepts multiple entries of the file field.
To specify metadata specific to a file, add the file name as a prefix to the metadata fields for that file, including version and policy. If a prefix is not specified, the field is considered general and it is added as metadata for all files.
Body Sample:
field | value |
---|---|
file | file1.jpg |
file | file2.jpg |
file1.jpg:version | 1 |
file2.jpg:version | 4 |
policy | merge |
file1.jpg:title | logo |
description | Logo image |
In this example, two files will be added:
- file1.jpg:
- version = 1
- policy = merge
- title = logo
- description = Logo image
- file2.jpg (no title field)
- version = 4
- policy = merge
- description = Logo image
Delete File
Deletes a file, given the file name, from a file scope of the specified record.
Request
The delete file DELETE/POST request requires the storage unit name, record key, scope name and the file name to delete. Additionally requires a JSON body with a version and delete policy.
- version: A version to chronologically identify the file transactions. If a file within record with the same file name already exists with a higher version, the file will not be deleted.
- policy: The policy to use when deleting the file from the scope of the record:
- silent (default): If the file doesn't exist in the record's scope, the request completes without an error.
- mustexist: If the file doesn't exist in the record's scope, an error is reported back in the response for the record.
Code Block | ||||
---|---|---|---|---|
| ||||
PUT transaction/deleteFile/<storage-unit>/<key>/<scope>/<filename> { "version":5, "policy":"silent" } |
Response
If the file is deleted correctly, a 200 response code and an OK message are returned.
Code Block | ||||
---|---|---|---|---|
| ||||
{"message":"OK"} |