jQuery-File-Upload预处理时文件数据在哪里? http://blueimp.github.io/jQuery-File-Upload/ [英] jQuery-File-Upload where is the file data when pre processing? http://blueimp.github.io/jQuery-File-Upload/

查看:83
本文介绍了jQuery-File-Upload预处理时文件数据在哪里? http://blueimp.github.io/jQuery-File-Upload/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've started playing around with the excellent http://blueimp.github.io/jQuery-File-Upload/ file upload project.

来自文档似乎jquery.fileupload-process.js会让我解析甚至修改文件的二进制文件data(文件数组 - 应用了进程的结果,originalFiles包含原始上传的文件)

From the File Processing Options section of the documentation it seems that jquery.fileupload-process.js will let me parse and even modify the file's binary data (files array - with the result of the process applied and originalFiles with the original uploaded files)

(解析,或附加或加密或执行某些操作)它)

(to parse, or append to it or encrypt it or to do something to it)

但是对于我的生活,我似乎无法弄清楚数组中的实际文件数据在哪里,以便我可以在之前预先处理它它上传。

but for the life of me I can't seem to figure out where is the actual file data within the array so that I can pre-process it before it uploads.

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

What part of the data array has the "something.pdf" binary file in it? so that I can parse and transform it before upload?

    //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?

谢谢。

推荐答案

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

The correct way to access the currently processed file is the following:

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

支持 File API ,这是一个File对象。

For browsers which support the File API, this is a File object.

要检索实际的文件数据,我们必须使用 FileReader 界面:

To retrieve the actual File data, we have to use the 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);

这篇关于jQuery-File-Upload预处理时文件数据在哪里? http://blueimp.github.io/jQuery-File-Upload/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆