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

标签 javascript html input truncate

在我的页面上,我使用 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 上,即使我们增加 maxlength,它也限制为 524288。属性。

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

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

相关文章:

Javascript数组映射函数保留数组先前项目的记录

javascript - 如何用 JavaScript 画一个简单的尺子?

html - 如何在垂直网站中使 div 部分响应

python - 如何在 Python 中读取整数命令行参数?

java - 捕获 gwt InputElement 的更改事件

javascript:IE 中的 getElementById 问题

javascript - 使用 CSS 隐藏空的可关闭 Bootstrap 警报?

html - div 样式 ="overflow:auto"在 IE 10 中无法正常工作

javascript - 更改不透明度不适用于 Chrome 中的 JS 和 SVG

html - 在 Bootstrap 中创建和样式化输入作为句子的一部分?