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!
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.
@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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With