What I have is a static website that should provide displaying a local image from the user’s computer. This website has no real backend, it is only hosted on a static fileserver. Also the image hasn’t to be processed on the server, all processing is made on the client’s machine from the website itself.
What I’ve tried:
-
Use local path.
Problem: Cross origin policy, if the website is hosted under “www.mywebsite.com”, no static files are supported in the browser. -
Use the imageshack.us API for uploading in an iframe, then get back the images’ url.
Problem: Cross origin policy, the iframe mustn’t transfer information to it’s parent if it’s content isn’t on the same domain.
Do you have any ideas how to solve this problem?
Thanks
You could use the
FileReaderAPI’sreadAsDataURLand use the returned data URL to display the image. MDN’s page has an example, that does just this, and you can see it working here.Note that the
FileReaderAPI is relatively new, and there is no support for it in IE <10. Browser SupportDemo of MDN’s code