Skip to content

Instantly share code, notes, and snippets.

@bortevik
Last active August 29, 2015 13:56
Show Gist options
  • Save bortevik/9324966 to your computer and use it in GitHub Desktop.
Save bortevik/9324966 to your computer and use it in GitHub Desktop.
Uploading Files with CORS and Ember.js
# View
RoscredAdmin.UploadFileView = Ember.TextField.extend
classNames: ['form-control']
attributeBindings: ['name']
type: 'file'
file: null
change: (event)->
fd = new FormData()
fd.append('pdf', event.target.files[0])
@set('file', fd)
# Controller
App.OtherController = Ember.Controller.extend
agreementPdf: null
actions:
savePdf: ->
return unless @get('agreementPdf')
$.ajax
url: "/pdf/upload_agreement",
type: 'POST'
contentType: false
processData: false
data: @get('agreementPdf')
# don't forget about CORS options
# Emblem
RoscredAdmin.UploadFileView name="pdf" file=pdf
button click="savePdf" Save
class PdfController < ApplicationController
def upload
File.open("public/uploads/some.pdf", "wb") { |file| file.write params[:pdf].read }
head :ok
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment