Skip to content

MatthiasKunnen/uploadcare-rest

Repository files navigation

Uploadcare Rest

npm version

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.

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');