javascript/AJAX文件上传 [英] javascript/AJAX file uploading
问题描述
我需要使用javascript/AJAX将本地文件上传到服务器.问题是如何选择文件并将其读入字节数组?
I need to upload a local file to server with javascript/AJAX. The problem is how can I select a file and read it into byte array?
PS:我无法使用HTML表单上传文件.
PS: I can't use HTML form to do the file uploading.
推荐答案
对于HTML5,有FileReader API.它使您可以读取用户选择的文件.前几天,我仅使用HTML5和JS构建CSV解析器.这也不难.
With HTML5, there is the FileReader API. It allows you to read the files that your users have selected. The other day I build a CSV parser using HTML5 and JS only. It wasn't hard at all either.
由于它是较新的api,因此不受很好的支持.在此处查看支持. http://caniuse.com/#search=filereader
Since it is a newer api, it isn't well supported. Check out the support here. http://caniuse.com/#search=filereader
如果您不想这样做,那么您将需要执行本杰明建议的Flash解决方案.
If you don't want to do that, then you will need to do the flash solution that Benjamin has suggested.
如果您需要更多信息,请转到此处.太棒了!!! https://developer.mozilla.org/en/DOM/FileReader
If you more info, go here. Pretty awesome!!! https://developer.mozilla.org/en/DOM/FileReader
这篇关于javascript/AJAX文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!