Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Rails CarrierWave

rnicholus edited this page Mar 26, 2013 · 1 revision

(Method A) Use hacked StringIO

The syntax looks like this:

file = AppSpecificStringIO.new(params[:qqfile], request.raw_post)

See https://github.com/jnicklas/carrierwave/wiki/How-to%3A-Upload-from-a-string-in-Rails-3 for detailed doc.

Also: https://groups.google.com/forum/#!topic/carrierwave/KBn2WmrwRAs

(Method B) Use rack-raw-upload middleware

You can use pretty rack-raw-upload gem for extract file from ajax request as standard rails file (params[:file]):

file = params[:qqfile].is_a?(ActionDispatch::Http::UploadedFile) ? params[:qqfile] : params[:file]
@photo = Photo.new(image: file)
if @photo.save
  render json: {:success => true, :src => @photo.image.url(:thumb)}
else
 render json: @photo.errors.to_json
end

See https://github.com/newbamboo/rack-raw-upload#ruby-on-rails.

Clone this wiki locally