JS API clients
JS API clients handle uploads and file operations by wrapping Uploadcare Upload API and REST API. You can use it from within your Node.js app and in a browser.
Features
Uploading (Upload API):
- Upload files from local storage and URLs (up to 5 TB)
- Multipart uploading for large files
- Track uploading progress
- Bulk file uploading
- Uploading network to speed uploading jobs (like CDN)
- Signed uploads
File management (REST API):
- Get file info and perform various operations (store/delete/copy) with them
- Manage metadata
- Manage webhooks
- Convert documents
- Encode and transform videos
- Secure authentication
Image processing (URL API):
- Compression
- Geometry
- Colors
- Definition
- Image and text overlays
- Rotations
- Recognition
- File info
- Proxy (fetch)
Requirements
Node.js 16 or later.
Install
Usage examples
To access the Upload Client High-Level API, you need to create an instance of UploadClient
providing the necessary settings. Specifying YOUR_PUBLIC_KEY is mandatory. It
points to the specific Uploadcare project:
Once the UploadClient instance is created, you can start using the wrapper to upload files from binary data:
Note: The store option accepts true, false, or "auto". String values like "true" or "false" are not accepted.
Signed uploads
For signed uploads, use the
@uploadcare/signed-uploads package. It mints the auth tokens that new projects
should use. Both packages need 6.23.0 or later. Upload Client versions that
predate authToken ignore it without a warning and the request goes out
unsigned.
In the browser, pass a function instead of a token and wrap your fetch in
AuthTokenCache. It refreshes the token before it expires and shares one fetch
across uploads that start together:
The /client entry point is browser-safe: it holds no signing code and never
touches your secret key. Call tokens.invalidate() when the signed-in user
changes. A short-lived token handles the rest on its own, and the cache holds
nothing across a reload: it lives in the instance, with no localStorage or
cookie behind it, so a fresh page always calls fetchToken again. A cache
built per request on a server is the same story, which is why one shared at
module scope would hand a visitor the previous visitor’s token. The
AuthTokenCache reference covers its remaining options, including
initialToken for a token rendered into the page during SSR, and what to watch
for when the cache runs on a server.
If your function throws, the upload rejects with an AuthTokenResolverError
carrying the original failure on cause. Nothing was sent, so nothing is
retried:
To tell a lost session from a dead endpoint, include your endpoint’s HTTP status
in what the function throws, then check it on error.cause: a 401 means the
user has to sign in again, while a 500 or a network error is worth retrying.
When Uploadcare refuses the token as expired (AccessTokenExpiredError) or out
of operations (OperationsLimitExceededError), the client calls
tokens.invalidate() for you, fetches a new token and retries the request once.
Reaching your handler with either code means the second token was refused too,
so invalidating again changes nothing: see
troubleshooting. This only
happens when authToken is a function or a cache; a plain token string is sent
as is and never retried. ScopeForbiddenError is never retried either, since a
reissued token carries the same scope.
The same package also generates the signature and expire pair:
Bulk uploads
Use Queue to control concurrency when uploading multiple files:
Error handling
Authentication
For server-side usage, use UploadcareSimpleAuthSchema:
Warning: Never use UploadcareSimpleAuthSchema on the client side: it exposes your secret key. For client-side usage, use UploadcareAuthSchema with a signatureResolver that delegates signing to your backend.
For client-side usage:
Pagination
Use the paginate helper to iterate through all pages of results:
File conversion
Convert video and document files using the unified convert API:
Search files
File tags
Full documentation
Read the full documentation on JS API clients GitHub.