0

I am new HTML5 and Ajax and I was wonder if it's possible with these technologies to write a service that would allow a user to upload an image for example in the background so they could continue browsing different pages on the same site while the upload is in progress?

  • It's possible if you start your upload from new window/tab. I'm afraid you can't just start upload and browse different page before upload has been finished, well, not in the same window/tab. – Wh1T3h4Ck5 Oct 05 '12 at 03:05

1 Answers1

3

XHR2 AJAX request can submit binary data like images:

https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications#Example.3A_Uploading_a_user-selected_file

However, changing the address bar (windows.location) will interrupt the upload as the new page is loaded. You can work around of this by loading pages via AJAX and using History API:

https://developer.mozilla.org/en-US/docs/DOM/Manipulating_the_browser_history

Optionally you can resize image on the client-side using <canvas> to decrease the needed bandwidth and the server load

Resizing an image in an HTML5 canvas

Also if you touch the image in <canvas> you might want to keep JPEG metadata, like rotation and GPS coordinates around,

https://github.com/miohtama/Krusovice/blob/master/src/tools/resizer.js

Community
  • 1
  • 1
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435