Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unfailing Javascript Image Preview

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)?

like image 491
Jason Avatar asked Apr 30 '10 22:04

Jason


1 Answers

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.

like image 78
Henrik Hansen Avatar answered Oct 30 '22 17:10

Henrik Hansen