如何在特朗博维格中添加云参数以上传插件



我在我的项目中使用了trumbowyg编辑器。从文档中,我知道可以使用以下代码来设置编辑器的图片上传内容。

$('#editor')
.trumbowyg({
    btns: ['upload'],
    plugins: {
        // Add imagur parameters to upload plugin for demo purposes
        upload: {
            serverPath: 'https://api.imgur.com/3/image',
            fileFieldName: 'image',
            headers: {
                'Authorization': 'Client-ID xxxxxxxxxxxx'
            },
            urlPropertyName: 'data.link'
        }
    }
});

这适用于imgur,但我想使用cloudinary服务器而不是imgur.

任何人都可以指导我在使用cloudinary时与plugins:{}做什么?

我也正在使用dropzone.js cloudinary上传图像,这也正常工作。以下是拖放区函数代码:

Dropzone.autoDiscover = true;
var myDropzone = new Dropzone(document.getElementById('image-upload'), {
  clickable: "#image-upload #btn-add",
  uploadMultiple: false,
  autoProcessQueue: true,
  acceptedFiles:'.jpg,.png,.jpeg,.gif',
  parallelUploads: 10,
  maxFilesize: 9,
  maxFiles: 10,
  url: 'https://api.cloudinary.com/v1_1/demo_project/image/upload',
  addedfile: function(file) {
    // console.log(file);
    new Noty({
      type: 'success',
      text: "Uploading...",
      timeout: false
    }).show();
    // myDropzone.processQueue();
  },
  success: function(file, response){
    new Noty({
      type: 'success',
      text: "Uploaded!",
      killer: true
    }).show();
    newImageArray.push({
      public_id: response.public_id,
      url: response.url,
      secure_url: response.secure_url
    });
    newImageArrayJSON = JSON.stringify(newImageArray);
    $imageStorage.val(newImageArrayJSON)
    $("#image-upload .image").html('<img src="' + response.secure_url + '">')
    $("#image-upload #btn-add").hide();
    $("#image-upload #btn-remove").show();
  }
});
myDropzone.on('sending', function (file, xhr, formData) {
  formData.append('api_key', 112233445566778);
  formData.append('timestamp', Date.now() / 1000 | 0);
  formData.append('upload_preset', 'mypreset');
});

提前感谢!

我建议从我测试并为我工作的以下基本实现开始:

$('#editor').trumbowyg({
    btns: ['upload'],
    plugins: {
        upload: {
            serverPath: 'https://api.cloudinary.com/v1_1/demo_project/image/upload',
            fileFieldName: 'file',
            urlPropertyName: 'data.secure_url',
            data: [
                {name: 'api_key', value: '112233445566778'},
                {name: 'timestamp', value: Date.now() / 1000 | 0},
                {name: 'upload_preset', value: 'mypreset'}
            ],
            success: function (data) {
                console.log(data);
            },
            error: function (error) {
                console.log(error.responseText);
            }
        }
    }
});

您可以登录到您的Cloudinary帐户并修改您的上传预设,以根据不同的条件限制上传,就像您对dropzone.js所做的那样,例如仅允许上传特定格式等。

最新更新