views:

613

answers:

2

I have the following code that presents the user with a preview of the image they're trying to upload and works really well in FF:

var img = document.createElement('img');
img.src = $('#imageUploader').get(0).files[0].getAsDataURL();

The problem is, getAsDataURL() only works in FF. Is there something similar/a workaround for this kind of functionality in Chrome (specifically)?

+2  A: 

If the browser doesn't support getAsDataURL you could make sure that the file input is instead using Gears' openFiles (scroll down) to read a file selected by the user. Google ain't working on Gears anymore, but it will work in Chrome, at least until getAsDataURL() gets implemented.

EDIT: Changed answer to be more helpful.

henrikh
A: 

Read this!

http://stackoverflow.com/questions/942105/file-data-from-input-element

aSeptik
...thanks? i think
Jason
Well, proved that, it can't be done in all browser with `getAsDataURL()` and also that JavaScript does not have any direct access to files on the visitor's computer for security reasons, what do you need!? if you want a solution, just use ajax or flash! if you want a demo, let me know! i'll make one for you in a minute! let me know!
aSeptik