gpt4 book ai didi

javascript - html 值正在 chop 我的字符串

转载 作者:行者123 更新时间:2023-11-27 23:52:42 25 4
gpt4 key购买 nike

在我的页面上,我使用 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??

有人可以向我解释我在 chop 这些数据时做错了什么吗?

谢谢,

最佳答案

如本 page 所述,文本类型的 input 的最大长度似乎至少在 Chrome 上是 524288。这就是你所拥有的......

我建议你把你的值存储在另一个地方!


编辑:

实现因浏览器而异:在 FF (v32) 上,我的长度可以大于 524288(我已经测试了 10.000.000),但在 Chrome 上它被限制为 524288,即使我们增加了 maxlength 属性。

关于这个问题还有一个 WebKit 的公开票:https://bugs.webkit.org/show_bug.cgi?id=44883

关于javascript - html 值正在 chop 我的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26016612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com