Permalink
Browse files

upload multiple files, wait for 1 second

  • Loading branch information...
1 parent 957aea6 commit 02c4770fc5a98e38c09c2fc754fcd7db2874ef8b @korny committed Mar 30, 2013
Showing with 18 additions and 1 deletion.
  1. +12 −1 app/assets/javascripts/welcome.js.coffee
  2. +6 −0 app/controllers/images_controller.rb
@@ -7,5 +7,16 @@ $(document)
$('body').removeClass 'dragging'
.on 'drop', (event) ->
files = event.originalEvent.dataTransfer.files
- alert "You just dragged #{files.length} file(s) into the browser."
+ window.setTimeout -> upload files
false
+
+upload = (files, index = 0) ->
+ if file = files.item(index)
+ formData = new FormData
+ formData.append 'file', file
+
+ $.ajax('/images', type: 'POST', data: formData, contentType: false, processData: false)
+ .done (data, textStatus) ->
+ upload files, index + 1
+ .fail ->
+ console.log 'Something went terribly wrong...'
@@ -21,6 +21,12 @@ def edit
# POST /images
def create
+ if params[:file]
+ Rails.logger.debug { params[:file] }
+ sleep 1
+ return head :ok
+ end
+
@image = Image.new(image_params)
if @image.save

0 comments on commit 02c4770

Please sign in to comment.