Dagang Wei
Dagang Wei

Reputation: 26458

javascript/AJAX file uploading

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.

Upvotes: 1

Views: 2767

Answers (3)

Mystro
Mystro

Reputation: 100

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

Upvotes: 0

frosty
frosty

Reputation: 21762

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

Upvotes: 3

Ben
Ben

Reputation: 13615

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

Upvotes: 1

Related Questions