html值正在截断我的字符串

时间:2014-09-24 12:11:51

标签: javascript html html5 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??

有人可以向我解释我错误地将这些数据截断了吗?

谢谢,

1 个答案:

答案 0 :(得分:2)

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

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


编辑:

不同浏览器的实现方式各不相同:在FF(v32)上,我的长度可能大于524288(我已经测试了高达10.000.000),但在Chrome上,即使我们增加了{{1},它仍然限制在524288 } attribute。

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