How to use the uploadcare-widget.openDialog function in uploadcare-widget

To help you get started, we’ve selected a few uploadcare-widget examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github netlify / netlify-cms / packages / netlify-cms-media-library-uploadcare / src / index.js View on Github external
const buildUrl = fileInfo => {
    const { cdnUrl, name, isImage } = fileInfo;

    let url =
      isImage && settings.defaultOperations ? `${cdnUrl}-${settings.defaultOperations}` : cdnUrl;
    const filenameDefined = !url.endsWith('/');

    if (!filenameDefined && settings.autoFilename) {
      url = url + name;
    }

    return url;
  };

  uploadcare.openDialog(files, config).done(({ promise, files }) => {
    const isGroup = Boolean(files);

    return promise().then(info => {
      if (isGroup) {
        return Promise.all(
          files().map(promise => promise.then(fileInfo => buildUrl(fileInfo))),
        ).then(urls => handleInsert(urls));
      } else {
        handleInsert(buildUrl(info));
      }
    });
  });
}

uploadcare-widget

Uploadcare Widget: file uploader.

BSD-2-Clause
Latest version published 3 months ago

Package Health Score

82 / 100
Full package analysis