在我的页面上,我正在使用HTML5在浏览器中上传文件。该文件是PDF文件,必须在文件中显示<input type="text"/>
这是我的代码:
var files = evt.target.files; // FileList object
// files is a FileList of File objects. List some properties.
for (var i = 0, f; f = files[i]; i++) {
console.log(f.name);
console.log(f.type);
console.log(f.size);
//Update document info
$("#document_filename").find("input").val(f.name);
$("#document_mimetype").find("input").val(f.type);
var reader = new FileReader();
// Closure to capture the file information.
reader.onloadend = (function(theFile) {
return function(e) {
content = e.target.result.replace(/^data:[^;]*;base64,/, "");
console.log(content.length);
$("#document_content").find("input").val(content);
a = document.getElementById("document_content").getElementsByTagName("input")[0];
a.value = content;
console.log(a.value.length);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
当我上传1.5MB的大文件时,控制台显示:
contrat.pdf // The file name
application/pdf // The file type
1510788 // The file size
2014384 // The length of the b64 content
524288 // The length of string once inserted in the input box??
有人可以告诉我我做错了什么导致该数据被截断吗?
谢谢,
如本页上所述input
,至少在Chrome上,“类型”文本可能的最大长度似乎为524288。这就是你所拥有的...
我建议您将价值存储在另一个地方!
编辑 :
具体实现方式因浏览器而异:在FF(v32)上,我的长度可以大于524288(我已经测试了10.000.000),但是在Chrome上,即使我们增加了maxlength
属性,它的长度也限制为524288 。
WebKit也有关于此问题的公开票证:https : //bugs.webkit.org/show_bug.cgi? id =44883
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句