Member Avatar

I was just wondering if it was possible to upload an image using XHR rather than a hidden iframe? If so, do all modern browsers support it?

Recommended Answers

This article talks about the XMLHttpRequest level 2 specification (still in development) which provides for direct file upload using the javascript XMLHttpRequest object (not iframes). Scroll down the page some for the new features that are being implemented.

Jump to Post

All 3 Replies

Sorry, but no. There is no way to access the image data.

The way to think about it is to remember the XMLHTTP sends well.. XML. Anything you want to send must be text encoded. Since there is no way to access a text representation of an image (or a file, or any other binary object) in javascript, then there is no way to send an image.

Sites that look like they are doing so usually use a small flash object with a fail over to using, as you said, a hidden frame.

see swfupload.

Uploading via XHR is not possible yet.
Use a flash or Java uploader.
Many websites make clever use of frames and AJAX to upload files and show progress bar....
And that's good!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.