gpt4 book ai didi

javascript - jQuery-File-Upload 预处理时文件数据在哪里? http ://blueimp. github.io/jQuery-文件上传/

转载 作者:行者123 更新时间:2023-12-01 02:20:47 24 4
gpt4 key购买 nike

我已经开始尝试优秀http://blueimp.github.io/jQuery-File-Upload/文件上传项目。

来自 documentation 的文件处理选项部分看来 jquery.fileupload-process.js 可以让我解析甚至修改文件的二进制数据(文件数组 - 包含应用过程的结果,originalFiles 包含原始上传的文件)

(解析、附加或加密或对其执行某些操作)

但就我而言,我似乎无法弄清楚数组中的实际文件数据在哪里,以便我可以在上传之前对其进行预处理。

数据数组的哪一部分包含“something.pdf”二进制文件?以便我可以在上传之前解析和转换它?

    //FROM: jquery.fileupload-process.js
//The list of processing actions:
processQueue: [
{
action: 'log'

}
],
add: function (e, data) {
var $this = $(this);
data.process(function () {
return $this.fileupload('process', data);
});
originalAdd.call(this, e, data);
}
},

processActions: {

log: function (data, options) {
console.log(data.files[0]); //Is it here?
console.log(data); //Is it here?
console.log(data.files[data.index]); //Is it here?
console.log(data.files[data.index].name); //Is it here?

//where?

谢谢。

最佳答案

访问当前处理的文件的正确方法如下:

var file = data.files[data.index];

对于支持 File API 的浏览器,这是一个 File 对象。

要检索实际的文件数据,我们必须使用 FileReader接口(interface):

var fileReader = new FileReader();
fileReader.onload = function (event) {
var buffer = event.target.result;
// TODO: Do something with the ArrayBuffer containing the file's data
};
fileReader.readAsArrayBuffer(file);

关于javascript - jQuery-File-Upload 预处理时文件数据在哪里? http ://blueimp. github.io/jQuery-文件上传/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20897896/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com