jQuery File Upload Plugin https://blueimp.net

我怕爱的太早我们不能终老 提交于 2019-12-24 23:26:40

问题


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:


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.



来源:https://stackoverflow.com/questions/50729816/jquery-file-upload-plugin-https-blueimp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!