Unicat API Reference

Up - API Reference - Home


/api/p/<project gid>/assets/upload

Requires JWT.

Uploading a file creates a new asset.

For uploading, we do NOT post JSON, but multipart formdata.

You specify the parent either by the gid in parent or by giving a pathname parameter.

If you provide both asset and pathname parameters, then we use parameter matching to guess what you meant. The first action that matches the parameters is performed, the rest is ignored. Parameter matching happens in the order given below:

Request multipart/form-data

POST /api/p/<project gid>/assets/upload
Authorization: Bearer <JWT>
Content-Type: multipart/form-data; charset=utf-8; boundary=__GENERATED_MULTIPART_BOUNDARY__

--__GENERATED_MULTIPART_BOUNDARY__
Content-Disposition: form-data; name="parent"

<parent gid>
--__GENERATED_MULTIPART_BOUNDARY__
Content-Disposition: form-data; name="upload_file"; filename="image.jpg"
Content-Type: image/jpeg

<image.jpg file data>
--__GENERATED_MULTIPART_BOUNDARY__--

or

POST /api/p/<project gid>/assets/upload
Authorization: Bearer <JWT>
Content-Type: multipart/form-data; charset=utf-8; boundary=__GENERATED_MULTIPART_BOUNDARY__

--__GENERATED_MULTIPART_BOUNDARY__
Content-Disposition: form-data; name="pathname"

/products
--__GENERATED_MULTIPART_BOUNDARY__
Content-Disposition: form-data; name="upload_file"; filename="image.jpg"
Content-Type: image/jpeg

<image.jpg file data>
--__GENERATED_MULTIPART_BOUNDARY__--

parent the parent's gid - it must be a folder.

pathname the parent's pathname - it must be a folder.

upload_file the file data for upload.

Success response

Authorization: <JWT>

{
    "success": true,
    "result": {
        "parent": "<parent asset gid>",
        "asset": "<asset gid>"
    },
    "data": {
        "assets": {
            "<asset gid>": {
                "gid": "<asset gid>",
                
            },
            "<parent asset gid>": {
                "gid": "<parent asset gid>",
                
            }
        }
    }
}

result

asset the newly created asset.
parent its parent with updated childcount.

data

assets Asset info with hierarchy, type, name. Unordered. Includes the parent asset with updated childcount and info.

Error responses

400 Bad request - missing parameters or wrong type or value
401 Unauthorized - missing or expired JWT
403 Forbidden - not a member of this project
422 Unprocessable entity - parent doesn't exist or isn't a folder or invalid file upload