Last active
August 29, 2015 13:56
-
-
Save bortevik/9324966 to your computer and use it in GitHub Desktop.
Uploading Files with CORS and Ember.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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