Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changing xhr to send FormData object

Instantiate the FormData object with rails csrf
then append the file to that object.
  • Loading branch information...
commit 59ad3346bcea7c6eae01e420bde708b59626369a 1 parent 9a45b58
@iterion authored
Showing with 11 additions and 8 deletions.
  1. +11 −8 lib/assets/javascripts/jack_up/file_uploader.coffee
View
19 lib/assets/javascripts/jack_up/file_uploader.coffee
@@ -1,10 +1,11 @@
-railsCSRFData = ->
+railsFormData = ->
csrfParam = $('meta[name=csrf-param]').attr('content')
csrfToken = $('meta[name=csrf-token]').attr('content')
- formData = {}
- formData[csrfParam] = csrfToken
- JSON.stringify formData
+ formData = new FormData()
+ formData.append(csrfParam, csrfToken)
+ #return the FormData object
+ formData
class @JackUp.FileUploader
constructor: (@options) ->
@@ -47,11 +48,13 @@ class @JackUp.FileUploader
xhr.open 'POST', @path, true
- xhr.setRequestHeader 'Content-Type', file.type
- xhr.setRequestHeader 'X-File-Name', file.name
- xhr.setRequestHeader 'X-Query-Params', railsCSRFData()
+ formData = railsFormData()
+
+ #append the file
+ #we should probably make the field name configurable
+ formData.append('file', file)
@trigger 'upload:start', file: file
- xhr.send file
+ xhr.send formData
_.extend JackUp.FileUploader.prototype, JackUp.Events
Please sign in to comment.
Something went wrong with that request. Please try again.