admin管理员组文章数量:1325361
I'm trying to upload a file into the browser and access it using JavaScript. Is this possible? I've looked around and it seems that you can acplish this using flash. I was trying to see if there was an HTML5/pure JavaScript solution.
I'm trying to upload a CSV file (each row contains a possible database entry) and validate it on the fly using javascript. If it passes validation, then I'll send a POST to the server to create the items.
I'm trying to upload a file into the browser and access it using JavaScript. Is this possible? I've looked around and it seems that you can acplish this using flash. I was trying to see if there was an HTML5/pure JavaScript solution.
I'm trying to upload a CSV file (each row contains a possible database entry) and validate it on the fly using javascript. If it passes validation, then I'll send a POST to the server to create the items.
Share Improve this question edited May 10, 2012 at 7:35 Rob W 349k87 gold badges807 silver badges682 bronze badges asked May 6, 2012 at 11:04 MarkMark 1,8572 gold badges13 silver badges6 bronze badges1 Answer
Reset to default 10This is possible. MDN offers a detailed explanation on this.
The following is a basic method to read a text file using the FileReader
API:
http://jsfiddle/tGpDG/
<input type="file" id="file_upload">
<script>
var input_file = document.getElementById('file_upload');
input_file.onchange = function() {
var file = this.files[0];
// Do something with the FileReader object
var reader = new FileReader();
reader.onload = function(ev) {
// Show content (ev.target === reader)
alert(ev.target.result);
};
// Read as plain text
reader.readAsText(file);
};
</script>
本文标签: javascriptClient side text file validation and uploadStack Overflow
版权声明:本文标题:javascript - Client side text file validation and upload - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742193740a2430693.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论