Skip to navigation

Security and authentication options

Options for signed uploads, authenticated requests, and secure delivery of uploaded files.

Related guides: File Uploader security, Secure uploads, Secure delivery.

See all options for the full list.

authToken Since v1.35.1

A token for signed uploads, sent with every Upload API request. Needs File Uploader 1.35.1 or later. Versions that predate the option ignore it without a warning and the upload goes out unsigned.

Pass a function and the uploader caches the token and replaces it 30 seconds before it expires, and retries an upload once with a new token when Uploadcare refuses the old one as expired or spent. A new function on each render, as in React, keeps the cached token. A plain token gets neither: it is sent as given, never refreshed and never retried, so its lifetime must cover the whole upload. Leave it unset to upload without a token. A function that returns nothing fails the upload with an AUTH_TOKEN_ERROR.

A { getToken, invalidate } object works in place of the function when you keep your own cache. An AuthTokenCache instance is already this shape, so you can pass one straight in. The uploader then adds none of its own and calls your invalidate() when a token is refused.

Takes precedence over secureSignature, secureExpire and secureUploadsSignatureResolver, which are dropped when it is set.

With React File Uploader this is an ordinary prop, function and all. On the web component, a function has to be set as a DOM property rather than an attribute. The auth-token attribute carries a plain token only, and writing it after setting a function replaces the function.

Signed uploads covers issuing the tokens, and invalidateAuthToken() drops a cached one.

Note: Replacing a token early needs a readable exp. A token the uploader cannot parse is cached and never refreshed on its own, so invalidate it yourself.

Attribute: auth-token

DOM property: authToken

Type: string | (() => string | Promise<string>) | { getToken, invalidate } | null

Default: null

secureSignature

Set signature for signed uploads. See the signature reference for details, or authToken for the token scheme recommended for new integrations.

Attribute: secure-signature

DOM property: secureSignature

Type: string

Default: ''

secureExpire

Set expire for signed uploads. See the signature reference for details.

Attribute: secure-expire

DOM property: secureExpire

Type: string

Default: ''

secureUploadsSignatureResolver Since v0.41.0

Works as DOM property only.

Set a function that resolves signed uploads signature and expire asynchronously.

This function will be called before each upload request in case when previous signature and expire are not set or expired.

There are a 10 minutes threshold for the expire value. If the expire value will be expired in 10 minutes, it will be considered as expired and a new value will be requested.

See security and the signature reference for details.

Attribute: -

DOM property: secureUploadsSignatureResolver

Type: () => Promise<{ secureSignature: string; secureExpire: string } | null>

Default: null

secureUploadsExpireThreshold Since v0.41.0

Works together with the secureUploadsSignatureResolver option. Sets the auto-refreshing threshold for signed uploads expire value in milliseconds.

Note: This applies to signatures only. An authToken is replaced by the uploader’s own cache 30 seconds before the token expires, and this option has no effect on it.

The expire value will be considered expired if the difference between the current time and the expire value is less than the threshold. In this case, a new signature and expire will be requested using the secureUploadsSignatureResolver function.

This is needed to prevent the expire value from expiring during the direct uploading method. Files less than 25 MB are uploaded directly to the Uploadcare servers, and the expire value will be checked after the file is uploaded, so it should be valid during the whole upload process.

Files larger than 25 MB are uploaded using the multipart upload method, and the expire value will be checked before the upload starts.

See security and the signature reference for details.

Attribute: secure-uploads-expire-threshold

DOM property: secureUploadsExpireThreshold

Type: number

Default: 10 * 60 * 1000 (10 minutes)

secureDeliveryProxy

Set a proxy URL template. See secure delivery docs for details.

Attribute: secure-delivery-proxy

DOM property: secureDeliveryProxy

Type: string

Default: ''

secureDeliveryProxyUrlResolver Since v0.41.0

Works as DOM property only.

Set a function that resolves the secure delivery proxy URL. It accepts the previewUrl and urlParts arguments and should return the resolved URL itself or a promise that resolves that URL.

Argument urlParts is an object with the deserialized URL parts:

  • uuid: file UUID.
  • cdnUrlModifiers: CDN URL modifiers (-/resize/100x/ or '' for example).
  • fileName: file name ('example.jpg' or '' for example).

See secure delivery docs for details.

Attribute: -

DOM property: secureDeliveryProxyUrlResolver

Type: (previewUrl: string, urlParts: { uuid: string; cdnUrlModifiers: string; fileName: string }) => Promise<string> | string

Default: null