Carrierwave upload to a tmp dir before saving to database

Posted by user827570 on Stack Overflow See other posts from Stack Overflow or by user827570
Published on 2012-06-24T09:11:04Z Indexed on 2012/06/24 9:15 UTC
Read the original article Hit count: 278

Filed under:
|
|

I'm trying to build a visual editor where users can click an image they are presented with an image upload form once the upload is done I use ajax to return the image and insert it back into the page.

But the above method inserts the image straight into the database but I want users to be able to visualize the image before the image is inserted into the database.

So I was wondering if the image using carrierwave could be uploaded to a temp location, sent back to the user and then when the user saves the page the image is moved into the permanent location.

Here's what I have so far.

def edit_image
  @page = Page.find(1)  
  @page.update_attributes(params[:page])
  @page.save
  return :text => @page.file
end

But this is what I want to achieve

def temp_image
  #uploads received image to a temp location
  #returns image to the user
end

And once the user clicks save

def save
  #moves the file in the temp folder to the permanent location 
end

Cheers

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about AJAX