jQuery文件上传插件https://blueimp.net [英] jQuery File Upload Plugin https://blueimp.net
问题描述
晚上好, 我想使用插件jQuery File Upload Plugin,但是我遇到了问题. 我使用的是base64图像,因为该图像会通过修剪工具进行剪切. 如何通过.fileupload()上传和上传base64格式的图像 我需要一个jQuery/PHP版本
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
推荐答案
摘自他们的文档: https://github.com/blueimp/jQuery-File-Upload/wiki/API#programmatic-file-upload
$('#fileupload').fileupload('add', {files: filesList});
第二个参数必须是带有数组的对象(或类似数组的对象 列表)的文件或Blob对象作为文件属性.
The second argument must be an object with an array (or array-like list) of File or Blob objects as files property.
所以听起来很简单:
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) {
...
}
});
似乎很灵活.
这篇关于jQuery文件上传插件https://blueimp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!