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

标签 javascript jquery jquery-file-upload blueimp

我已经开始尝试优秀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/

相关文章:

javascript - 如何正确链接包含在 Promise 中的不同异步操作

javascript - 无法将 undefined 转换为对象?

Javascript OOP 回调 "this"应用

javascript - 仅对 JQuery 中悬停的元素产生影响。 - 相同的类(class)

javascript - 格式化日期选择器以发布到 MySQL 数据库

jquery - 单击 <a> 标签更改 <li> 的背景图像

jquery - 限制多个文件的上传大小

jQuery-File-Upload插件,如何确认多次删除?

Blueimp 的 jQuery 文件上传 : hide existings files

javascript - 如何在 Visual Studio .NET 2008 中保留 JavaScript 全局变量的智能感知