Forum Moderators: open

Message Too Old, No Replies

AJAX Form - image upload?

image uploading using forms and ajax

         

Klipklouter2

9:32 am on Jul 16, 2006 (gmt 0)

10+ Year Member


Does anybody have any ideaa how to send an image to the server using ajax? i tried a form, but prototype's form sending doesnt support multipart/form-data.

I'm building a kewl site that NEVER reloads, but this image upload is vital... Any suggestions (no im not using iframes!)

Thanks, please send to ajax@therockalley.com, or drop a comment here! thanks

Little_G

11:07 am on Jul 16, 2006 (gmt 0)

10+ Year Member



Hi,

I'm almost certain that that's not possible, browsers only allow access to external files through the file input element for security reasons, and again for security reasons the form cannot be submitted without the page changing.
The only method I can think of is to use 'target="_blank"' in the form which will open a new window which you could then close with JavaScript.

Andrew

Rambo Tribble

8:06 pm on Jul 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look into <input type="file" />

supermoi

1:59 pm on Jul 19, 2006 (gmt 0)

10+ Year Member



From what I know it is impossible to upload a file in ajax. However there is a workaround but it is very complicated and your clients have to have javascript enabled to read files on their computer (which is usually a very big security issue). In this case, you can read the file in javascript and create a binary representation of the file that you send to the server as a string. The server can then recreate the file from the string.
The only other method to upload a file with not visible reloading is the send the form in a hidden iframe (which could be created on-the-fly with javascript and then removed) or in a popup window as you suggested.