1
votes

I am uploading an image to amazon s3 using rails, and the url being returned is incorrect. however, I have noticed that the correct url is available in the :key, looking at my dev server log:

Started GET "/product/add?index=0" for 96.250.13.59 at 2014-06-14 13:04:39 -0400 Processing by ProductsController#saveProduct as HTML Parameters: {"index"=>"0"} "http://s3-us-west-2.amazonaws.com/vigme/products/image_s3s//original/goods_09_086661?1402765480" (0.3ms) BEGIN SQL (4.5ms) INSERT INTO products (buy_url, ftp_transfer_datetime, ftp_transfer_deleted_source, ftp_transfer_deleted_source_datetime, ftp_transfer_processed, image_s3_content_type, image_s3_file_name, image_s3_file_size, image_s3_updated_at, image_s3_url) VALUES ('http://www.uniqlo.com/us/women/outerwear/jackets-and-coats/stretch-tailored/women-stretch-tailored-jacket-086661.html#08', '2014-06-14 17:04:40', 1, '2014-06-14 17:04:40', 1, 'image/jpeg', 'goods_09_086661', 19478, '2014-06-14 17:04:40', 'http://s3-us-west-2.amazonaws.com/vigme/products/image_s3s//original/goods_09_086661?1402765480') [paperclip] saving /products/image_s3s/001/855/192/original/goods_09_086661 [AWS S3 200 0.845202 0 retries] put_object(:acl=>:public_read,:bucket_name=>"vigme",:content_length=>19478,:content_type=>"image/jpeg",:data=>Paperclip::HttpUrlProxyAdapter: goods_09_086661,:key=>"products/image_s3s/001/855/192/original/goods_09_086661")

The last symbol, :key, contains the right url if added to the the amazon s3 url. However, it is returning the url on top. How do i fix this?

1

1 Answers

0
votes

Okay, I figured out the answer myself, so just posting to help anyone who's finding the similar problem. The problem was that I was not saving the product after assigning the url of an image to an instance of the product. Therefore, s3 was not asked to return a url for the image, as the image was not yet saved in the bucket. e.g.

product.image_s3 = url_for_image
product.save

# now i can access it
s3_image_url = product.image_s3.url

as opposed to earlier, where I was trying to do:

product.image_s3 = url_for_image
s3_image_url = product.image_s3.url
product.save