I have a rails-api in which I'm using paperclip to store the images and these images are getting stored on an S3 bucket.
This is the heroku log when I do a upload.
[paperclip] saving /feeds/images/000/000/025/original/test.png
2016-08-10T07:53:14.814789+00:00 app[web.1]: [AWS S3 200 0.480788 0 retries] put_object(:acl=>:public_read,:bucket_name=>"",:content_length=>589015,:content_type=>"image/png",:data=>Paperclip::UploadedFileAdapter: test.png,:key=>"feeds/images/000/000/025/original/test.png")
What I want to do is to retrieve the link where this image is stored that is, /feeds/images/000/000/025/original/test.png and store it in my database for future downloads. Can someone point out to how I can access this key field?
I know S3 will save it at a default location each time like /model/object/000/000/(id of new record)/original/file_name, but I want to access the exact location where it has stored the image and not just make a conjecture.
EDIT 2
The problem of retrieving has solved but storing the links is still kind of shaky.
This is my method where I'm taking in the image
def create
id = params[:uid]
msg = params[:message]
img = params[:image]
feed = Feed.new({user_id: id, message: msg, like_count: 0, comment_count: 0, image: img})
feed.imageurl = feed.image.url(:medium)
feed.smallimageurl = feed.image.url(:thumb)
if feed.save
render json: feed.as_json(only:[:id]), status:201
else
render json: {errors: "Could not create post"}, status: 422
end
end
When I upload any image it's storing the link as "http://s3.amazonaws.com/example/feeds/images//medium/458989879.jpg?"
See how the /000/000/026 is missing in between images and medium?
However when I do this Feed.find(26).image.url(:medium)
"http://s3.amazonaws.com/example/feeds/images/000/000/026/thumb/458989879.jpg?"
I know where the problem lies, it's that I need to store the image link after it's been stored to S3 or something.