uploadcare-rest
v2.0.1
Published
A node library to execute Uploadcare's REST requests
Downloads
21
Readme
Uploadcare Rest
This is a wrapper around the API made available by uploadcare. The library is written in TypeScript and has typings available.
The methods will be implemented gradually.
Versions:
- ^1.0.0, CommonJS, Node >= 6
- ^2.0.1, CommonJS and ESModules, Node >= 18
Currently implemented
Files
- copy
- remove
- store
Example
const uploader = new Uploadcare(
config.uploadcare.publicKey,
config.uploadcare.privateKey,
);
// Copy a file to the CDN storage, for example a crop preview
const response = await uploader.files.copy(cdnUrlOrId);
const image = response.data;
// Check the type of the image. url for custom storage, file otherwise.
if (image.type === 'file') {
// Type cast for TypeScript only
const result = <UploadImageResult>image.result;
}
Upload
Example
const uploader = new Uploadcare(
config.uploadcare.publicKey,
config.uploadcare.privateKey,
);
const file = await uploader.upload.awaitFromUrl('https://picsum.photos/200/300/?random');
// That's all, the library takes care of checking the upload progress
// If you're not interested in waiting for the file, use the following
const idc = await uploader.upload.fromUrl('https://picsum.photos/200/300/?random');