1

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: I can't use HTML form to do the file uploading.

3 Answers 3

3

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.

Since it is a newer api, it isn't well supported. Check out the support here. http://caniuse.com/#search=filereader

If you don't want to do that, then you will need to do the flash solution that Benjamin has suggested.

If you more info, go here. Pretty awesome!!! https://developer.mozilla.org/en/DOM/FileReader

1
  • If you use the filereader, then you could read the file to bytes, and then using ajax send it to the server.
    – frosty
    Sep 2, 2011 at 2:02
1

You either use a Iframe with a HTML form or flash (theres no way to convert a file to a byte array using javascript)

http://www.uploadify.com/faqs/ (javascript and flash)

http://aquantum-demo.appspot.com/file-upload (javascript and iframe)

Please note that flash will not work on ipad, iphone and all other mobile apple

0

use this plugin it just worked for me . http://hayageek.com/docs/jquery-upload-file.php And the fun part it takes all files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.