Skip to content

Instantly share code, notes, and snippets.

@niuage
Created August 28, 2012 03:15
Show Gist options
  • Save niuage/3494620 to your computer and use it in GitHub Desktop.
Save niuage/3494620 to your computer and use it in GitHub Desktop.
# extracted from http://www.html5rocks.com/en/tutorials/file/dndfiles/
handleFileSelect = (event) ->
files = event.target.files
for file in files
continue if !file.type.match('image.*')
reader = new FileReader
reader.onload = displayImage
reader.readAsDataURL(file);
displayImage = (event) ->
$('<img/>').attr('src', event.target.result).appendTo 'body'
$ ->
$('#file-field').change handleFileSelect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment