[go: up one dir, main page]

Skip to content

uploadcare/uploadcare-tinymce

Repository files navigation

File Uploader by Uploadcare

This is a plugin for TinyMCE, a WYSIWYG HTML editor, providing it for working with Uploadcare Widget.

The plugin allows TinyMCE users to upload media from their devices, social media, cloud storage, and more. All that without any backend code that's usually required to handle uploads.

GitHub release  Uploadcare stack on StackShare

Demo

Requirements

Supported TinyMCE versions: 6.x, 5.x and 4.x.

Install

Download the latest plugin archive from the release branch or releases page.

Extract the downloaded archive to the plugin directory of your TinyMCE installation.

Another option here is cloning the repo:

git clone -b release git@github.com:uploadcare/uploadcare-tinymce.git plugins/uploadcare
  • uploadcare.tinymce@6.x - compatible with TinyMCE 6.x
  • uploadcare.tinymce - compatible with TinyMCE 4.x and 5.x

Usage

Add uploadcare to the list of your TinyMCE plugins and the toolbar. Set your public key. Public keys are used to identify a target Uploadcare project your uploads will go to.

tinymce.init({
  selector: '#editor',
  plugins: 'uploadcare',
  toolbar: 'uploadcare',
  external_plugins: {
    uploadcare: '/path/to/uploadcare/plugin.js',
  },
  // options example for 6.x
  uploadcare: {
    publicKey: 'YOUR_PUBLIC_KEY'
  }
  // options example for 4.x and 5.x
  uploadcare_public_key: 'YOUR_PUBLIC_KEY',
})

Configuration

Plugin configuration

To apply a custom configuration, initialize the TinyMCE editor providing additional options.

Here is example for TinyMCE 6.x:

tinymce.init({
  selector: '#editor',
  plugins: 'uploadcare',
  toolbar: 'uploadcare',
  external_plugins: {
    uploadcare: '/path/to/uploadcare/plugin.js',
  },
  uploadcare: {
    publicKey: 'YOUR_PUBLIC_KEY',
    /* when handling images, you can resize them on a client to save bandwidth */
    imageShrink: '500x375',
    /* allow multi-file uploads */
    multiple: true,
    multipleMax: 3,
    /* set crop options when handling images */
    crop: '1:1,4:3',
    /* feel free to add more options here */
  }
})

Example for TinyMCE 4.x and 5.x:

tinymce.init({
  selector: '#editor',
  plugins: 'uploadcare',
  toolbar: 'uploadcare',
  external_plugins: {
    uploadcare: '/path/to/uploadcare/plugin.js',
  },
  uploadcare_public_key: 'YOUR_PUBLIC_KEY',
  /* when handling images, you can resize them on a client to save bandwidth */
  uploadcare_image_shrink: '500x375',
  /* allow multi-file uploads */
  uploadcare_multiple: true,
  uploadcare_multiple_max: 3,
  /* set crop options when handling images */
  uploadcare_crop: '1:1,4:3',
  /* feel free to add more options here */
})

You can use any widget options providing those as object keys. Just add the uploadcare_ prefix and use snake_case instead of camelCase in option names, e.g. imagesOnlyuploadcare_images_only.

Widget configuration

Uploadcare Widget can be deeply customized to suit your UX/UI. You can define allowed upload sources, implement file validation, and more.

Use our live widget sandbox as a starting point and consider checking out the docs on widget configuration and its JavaScript API.

Effects Tab

To enable Effects Tab for Uploadcare Widget, you need to add init_instance_callback callback to the options of TinyMCE's init method with the following code:

tinymce.init({
  selector: '#editor',
  plugins: 'uploadcare',
  toolbar: 'uploadcare',
  external_plugins: {
    uploadcare: '/path/to/uploadcare/plugin.js',
  },
  init_instance_callback: function() {
    window.UPLOADCARE_EFFECTS = 'crop,rotate,mirror';

    function onSuccess() {
      uploadcare.registerTab('preview', uploadcareTabEffects)
    }

    tinymce.ScriptLoader.add('https://ucarecdn.com/libs/widget-tab-effects/1.x/uploadcare.tab-effects.js', onSuccess)
    tinymce.ScriptLoader.loadQueue()
  }
})

Security issues

If you think you ran into something in Uploadcare libraries which might have security implications, please hit us up at bugbounty@uploadcare.com or Hackerone.

We'll contact you personally in a short time to fix an issue through co-op and prior to any public disclosure.

Feedback

Issues and PRs are welcome. You can provide your feedback or drop us a support request at hello@uploadcare.com.