I want to load an image file from the computer directly to any js object without using any server-side component. For example, I want to select a picture from the local machine and display it on a webpage. Is there a way to avoid file upload to the server?
In fact I want to write a kind of multiple image loader, but before loading to the server I want to rotate some images, create an xml-file with some data like user id, image file names list and to zip all images and this xml and then send it to the server. How can I do that on the client side?
There is a way with HTML5, but it requires the user to have dropped the file into a drop target or used a
<input type="file"/>box, since otherwise it would be a security issue.Using the
FileAPI you can read files, and specifically you can use theFileReader.readAsDataURLmethod to set the content as adata:URL for the image tag.Here’s an example:
http://jsfiddle.net/alnitak/Qszjg/