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,