Skip to main content
Upload Image
Uploads an image, processes it, and stores the original plus all requested variants. Returns the File with its image data and a signed link to every variant. The links expire at the File’s linksExpireAt (File links): store the file’s id, not a link. The uploaded file isn’t attached to anything: it has no entity, comment, space or event. A file that belongs to a record is sent with that record’s own request (for example, the images and files of Create Entity or Create Comment, or the cover of Update Event). This endpoint accepts multipart/form-data. Requires an authenticated user. Rate limit: 20 requests per 5 minutes.

Body Parameters

file
required
The image file to upload: JPEG, PNG or WebP. Maximum 50 MB, and from 1 × 1 to 10000 × 10000 px.
string
required
Stringified JSON: the image-processing options, one object. These are the same options, with the same rules, as an inline <field>.options (for example avatarFile.options on Update User or images.options on Create Entity). Must include mode, and takes only the fields below for that mode: any other key, a key of another mode included (for example sizes with exact-dimensions), and any unknown key inside dimensions, aspectRatio or aspectRatios, is refused with 400 storage/invalid-body. A request without file.options gets 400 storage/missing-image-options; options that aren’t valid JSON or valid image options (mode missing included) get 400 storage/invalid-body.
string
Stringified JSON object of custom key-value data stored on the file. The server adds originalFilename, originalFormat and originalDimensions (the uploaded image’s own name, format and size) alongside, replacing any values of yours under those keys. Anything other than a JSON object is refused with 400 storage/invalid-body.
string
Service key only: the user this request acts as, who owns the uploaded file; the upload runs under that user’s own checks. Leave it out to upload an app-owned file with no owning user. A user that doesn’t exist returns 404 storage/user-not-found. A user token always acts as its own user and must not send it (400 storage/acting-user-not-allowed).

Response

201 Created with the File, the same shape Fetch File returns, its image data included. originalSize, originalMimeType and the image’s originalWidth and originalHeight describe the stored original: the image in its output format, shrunk to originalMaxSize.

Error Responses

Returned with no JSON body: 401 when no Authorization header is sent, 403 when the access token is invalid or expired. Checked before any uploaded file is read, so a request with no credentials gets 401 rather than a body or acting-user error.
A user token sent actingUserId, even naming its own user. Only a service key names the user it acts as; a user token always acts as its own user.
The request sent an image option as its own field: mode, dimensions, aspectRatio, widths, heights, sizes, aspectRatios, fit, quality, format, stripExif, originalMaxSize or pathParts. They go inside file.options. Refused even next to a valid file.options, and nothing is stored. param names the field:
The request sent position. A file uploaded here belongs to no record, so nothing is stored:
The request sent entityId, commentId, spaceId or eventId. A file uploaded here isn’t attached to anything, so these fields are refused rather than ignored, and nothing is stored. param names the field:
The request sent userId. On this route the user a service key acts as is actingUserId.With a service key:
With a user token:
file.options or metadata was refused. Nothing is stored. error names the field first, and param names it alone.file.options without mode, or with a mode that isn’t one of the five:
file.options isn’t valid JSON:
A folder in pathParts is refused:
In an aspect-ratio mode, a variant’s computed side would be outside 1–10000 px. Checked once the image is read, before anything is processed or stored. param names the option:
In aspect-ratio-height-based it names a heights option and gives a width. In multi-aspect-ratio it names a sizes option, and the ratio is the one in aspectRatios closest to this image: “file.options.sizes.s gives a height of 0 px at the 3:1 aspect ratio, the one in `aspectRatios` closest to this image. Each side of a variant must be 1–10000 px.”A key file.options doesn’t take, here or in one of its nested objects. error names the object holding it, param the key itself; several unknown keys are listed together (“Unrecognized keys: “a”, “b"") and param names the first:
More than 30 entries in dimensions, widths, heights or sizes. param names the option:
A variant name that uses a character other than letters, digits, _, - and ., that is longer than 64 characters, that contains .., or that is original. param names the option:
Any other value outside its rules (a size outside 1–10000, an originalMaxSize outside 50–10000, a fit the mode doesn’t take, metadata that isn’t a JSON object) gets the same code, with param naming the value.
The file can’t be read as a JPEG, PNG or WebP image:
The image is over 10000 px on a side. error gives its size:
The request sent no file.options. Checked after the image itself is checked, and nothing is stored.
Returned when a service key names an actingUserId that isn’t a user in this project. Checked before the upload.
A file was refused as the body was read: storage/unsupported-file-type or storage/unexpected-file-field, with param naming the field when there is one. A body over 250 MB gets 413 request/body-too-large; one that can’t be read at all gets request/invalid-multipart or request/field-too-large. See Upload errors.