jQuery File Upload Plugin https://blueimp.net

2019-08-20 12:17发布

Good evening, I would like to use the plugin jQuery File Upload Plugin but I have a problem. I'm using a base64 image, because the image passes through a trimming tool to cut the image. How can I upload and upload an image in base64 format via .fileupload () I need a jquery / php version

I can not find solutions, thanks in advance Sincerely

1条回答
戒情不戒烟
2楼-- · 2019-08-20 12:40

From their documentation: https://github.com/blueimp/jQuery-File-Upload/wiki/API#programmatic-file-upload

$('#fileupload').fileupload('add', {files: filesList});

The second argument must be an object with an array (or array-like list) of File or Blob objects as files property.

So sounds like it is as simple as:

var blob = ... //you said in the comments you've got the blob...
var blob = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
$('#fileupload').fileupload('add', {files: [blob]})

Now, I've also come across some more complex code (source) that suggests something like this is also possible:

$('#fileupload').fileupload({
    autoUpload: true,
    add: function (event, data) {
      $.ajax({
        url: "/upload",
        type: 'POST',
        dataType: 'json',
        data: {doc: {title: data.files[0].name}},
        async: false,
        success: function(response) {
          ...
        }

      });

Seems pretty flexible.

查看更多
登录 后发表回答