I have a simple app that uploads picture that i am saving using carrierwave in blog database. (having title,body and image) and my credentials are working fine.
I have an image uploaded in s3 account with this url: /s3.amazonaws.com/Buket_name/..path../thumb_smile.png
How can I update database with image from heroku rails console. This doesnt seem to work:
b = Blog.new
b.title = "a blog"
b.body = "some text"
b.image = File.new("s3.amazonaws.com/Buket_name/..path../thumb_smile.png","a")
or
b.image = File.open("s3.amazonaws.com/Buket_name/..path../thumb_smile.png","r")
Errno::ENOENT: No such file or directory -
s3.amazonaws.com/Buket_name/..path../thumb_smile.png
Use CarrierWave's remote_{name}_url=
attribute for the easiest solution.
b = Blog.new
b.title = "a blog"
b.body = "some text"
b.remote_image_url = 'http://s3.amazonaws.com/Buket_name/..path../thumb_smile.png'
b.save
This functionality is specific to CarrierWave, so if you are looking to do something similar with another library, use open-uri
from the standard library.
require 'open-uri'
image = open('http://s3.amazonaws.com/Buket_name/..path../thumb_smile.png')
Now image is a Tempfile
that can be used like a file in your Ruby script.
require 'open-uri'
image = open('http://s3.amazonaws.com/Buket_name/..path../thumb_smile.png')
b = Blog.new
b.title = "a blog"
b.body = "some text"
b.image = image
b.save
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