晚上好, 我想使用插件jQuery文件上传插件,但我有一个问题。 我正在使用base64图像,因为图像通过修剪工具来剪切图像。 如何通过.fileupload()上传和上传base64格式的图像 我需要一个jquery / php版本
我提前感谢找不到解决方案 此致
答案 0 :(得分:0)
从他们的文档:https://github.com/blueimp/jQuery-File-Upload/wiki/API#programmatic-file-upload
$('#fileupload').fileupload('add', {files: filesList});
第二个参数必须是带有数组的对象(或类似数组的对象) list)将文件或Blob对象作为文件属性。
听起来就像它一样简单:
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]})
现在,我还遇到了一些更复杂的代码(source),它们表明这样的事情也是可能的:
$('#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) {
...
}
});
似乎很灵活。