html值正在截断我的字符串 [英] html value is truncating my string
问题描述
在我的页面上,我使用HTML5在浏览器上上传文件。该文件是一个PDF文件,必须在< input type =text/>
这是我的代码:
var files = evt.target.files; // FileList对象
//文件是File对象的FileList。列出一些属性。
for(var i = 0,f; f = files [i]; i ++){
console.log(f.name);
console.log(f.type);
console.log(f.size);
$ b $ //更新文档信息
$(#document_filename)。find(input)。val(f.name);
$(#document_mimetype)。find(input).val(f.type);
var reader = new FileReader();
//关闭捕获文件信息。
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);
//将图像文件读入数据URL。
reader.readAsDataURL(f);
}
当我上传1.5MB大文件时,我的控制台显示:
contrat.pdf //文件名
application / pdf //文件类型
1510788 //文件大小
2014384 // b64内容的长度
524288 //输入框中插入字符串的长度?
有人可以向我解释我做错了什么来截断数据吗?
谢谢, 解决方案
正如 page ,文本类型的
我建议你在另一个地方储存你的价值!
编辑:
实现因浏览器而异:在FF(v32)上,大于524288(我已经测试过10.000.000),但在Chrome上,它被限制为524288,即使我们增加了 maxlength
属性。
关于此问题,还有一个针对WebKit的公开门票: https ://bugs.webkit.org/show_bug.cgi?id = 44883
On my page I am using HTML5 to upload a file on my browser. The file is a PDF an have to show it in a <input type="text"/>
This is my code:
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);
}
When I upload a big file 1.5MB, my console is showing:
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??
Can someone explain to me what I am doing wrong to get this data truncated?
Thanks,
As stated on this page, the maximum length possible for an input
of type text seems to be 524288 at least on Chrome. And this is what you have...
I suggest you storing your value in another place!
EDIT :
The implementation varies across browsers : on FF (v32), I can have length greater than 524288 (I have tested up to 10.000.000), but on Chrome it is limitated to 524288 even though we increase the maxlength
attribute.
There is also an open ticket for WebKit about this issue : https://bugs.webkit.org/show_bug.cgi?id=44883
这篇关于html值正在截断我的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!