Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload a local file to a Carrierwave model?

I'm using Carrierwave to handle image uploads, but I'm not using a form, instead I use local files in the server.

How can I make this work?

@user = User.first
image_path = "/tmp/pic-s7b28.jpg"

@user.image = image_path
@user.save!
like image 880
CodeOverload Avatar asked Apr 22 '13 00:04

CodeOverload


People also ask

How do I upload multiple images in rails?

A file can be uploaded to server in two ways, one we can send the image as base64 string as plain text and another one is using multipart/form-data . The first one is the worst idea as it sends the entire image as plain text.


1 Answers

@user = User.first
image_path = "/tmp/pic-s7b28.jpg"

@user.image = File.open(image_path)
@user.save!

You can check examples in the carrierwave readme

like image 151
ole Avatar answered Oct 08 '22 01:10

ole