ide*_*ead 2 javascript jquery blueimp jquery-file-upload
我开始使用优秀的 http://blueimp.github.io/jQuery-File-Upload/文件上传项目.
从文档的文件处理选项部分看来,jquery.fileupload-process.js似乎可以解析甚至修改文件的二进制数据(文件数组 - 应用了进程的结果,原始文件包含原始上传的文件)
(解析,附加或加密或对其做某事)
但对于我的生活,我似乎无法弄清楚数组中的实际文件数据在哪里,以便我可以在上传之前对其进行预处理.
数据数组的哪一部分有"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?
Run Code Online (Sandbox Code Playgroud)
谢谢.
小智 5
访问当前处理的文件的正确方法如下:
var file = data.files[data.index];
Run Code Online (Sandbox Code Playgroud)
对于支持File API的浏览器,这是一个File对象.
要检索实际的File数据,我们必须使用FileReader接口:
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2397 次 |
| 最近记录: |