How to map already uploaded s3 image with ActiveStorage - ruby-on-rails

My workflow
I have created a bucket in s3.
When somebody drops an image over there an SNS notification comes to my rails app in response got the image name.
By the image name, I can get the user info.
Now I need to create an active storage relation with the user which will map that s3 URL in active storage table.

Can the rails app access the file through s3?
You can attach an existing using an IO object as documented here:
https://edgeguides.rubyonrails.org/active_storage_overview.html#attaching-file-io-objects

Related

I am getting an error when trying use Cloudinary storage, Must Supply API key?

I am a student and new to Cloudinary and API credentials. I was trying to use Cloudinary storage and image upload for my app. After adding my credentials and running by command EDITOR="code --wait" rails credentials:edit accidentally I pressed Control + C on Credentials.
Now when I try to upload image I get the following error. Can it be because I pressed control + c or can it be some other API key error. How can I fix this error please?
This error means that the app can't find your Cloudinary credentials. You can use the following page - https://cloudinary.com/documentation/rails_integration#configuration - to choose one of the 3 ways to supply the Cloudinary credentials (cloud_name, api_key and api_secret) in your Rails app. For example, using the cloudinary.yml file which you can download from your Cloudinary Dashboard directly and place it in the config folder inside your app's directory.

I've uploaded an image for my website on s3 but it doesn't display on my website

I've uploaded an image for my website on s3 but it doesn't display on my website. It works fine on my localhost, as the picture is in my assests/images folder of my Rails 5 app, but not on Heroku. When I inspect my page, I do see an error for the file my code is looking for: Failed to load resource: the server responded with a status of 404 (Not Found) .I do believe I have my Heroku set up right with my amazon s3 bucket because I can see users' pictures being sent to it. I'm looking to use this picture as a background for part of my landing page. Any help would be great, thanks.
I made the image inside my 's3 bucket' public so that it could be accessed by my website. Also, I changed my url for the image in my Rails app to the new url provided by amazon s3.

iOS AWS S3 Transfer Utility not uploading

I've implemented this tutorial exactly, and i'm able to successfully upload an image to a s3 bucket using the uploadData method (the completion handler block runs with error=nil). My problem is that I can't see the file in the bucket when i'm looking through the AWS console, so I'm not sure if the image was uploaded successfully and due to wrong permissions or something like that I can't find it or if the image was not really uploaded.
Any idea what's wrong ?
Edit -
I've added permissions to the S3 bucket in the role policy of the new Cognito pool id that I've created for the client authentication purposes, but still no help.
Edit 2 -
I've also opened permissions on the bucket itself to everyone.
Make sure your bucket was created in the same region as your Cognito pool ids.

How to display a paperclip image in an email?

I have a photo saved for a user.
I want to be able to send them an email and include their photo.
In the actionmailer email view I have
<%= image_tag #user.photo.url(:medium) %>
The photo's filename is included in the email as text.
How do I embed/show the actual photo?
Paperclip is used to add the photo and AWS S3 is used to store the photo.
The link looks almost correct except for a few numbers at the end
http://s3.amazonaws.com/applicantlabs/applications/photos/000/000/011/medium/breakingnews-img_2x-ipad.png?1431789984
and when I click on the link the page displays the following error
<Error>
<Code>PermanentRedirect</Code>
<Message>
The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
</Message>
<Bucket>applicantlabs</Bucket>
<Endpoint>applicantlabs.s3.amazonaws.com</Endpoint>
<RequestId>30457ECCCF09A</RequestId>
<HostId>
igkrUR0P/wes3aqpT7nAj2U7KXK91Qs+RBxwufjex15MPN5z1UCK8F2WSg6q0
</HostId>
</Error>
To use this Paperclip S3 setup my S3 bucket had to be of type "US Standard". As this was a new app with no images in the bucket, I just created a new "US Standard" S3 bucket.

Heroku app not pulling S3 images on other machines

I recently added photo uploading to a web application that I'm hosting on heroku. I'm using S3 for storage and it's working great, however when other users go onto the site, they see a photo missing icon rather than the photo. On my machine however, I see the photos on the site. Any clues as to what is happening? Thanks!
When you upload your photos to s3 you need to set their access level to public using whatever s3 lib your using.
Here's snippet from s3 api docs:
x-amz-acl
The canned ACL to apply, to the object
that is created after completing
multipart upload. For more
information, go to REST Access Policy
in the Amazon S3 Developer Guide.
Type: String
Default: private
Valid Values: private | public-read |
public-read-write | authenticated-read
| bucket-owner-read |
bucket-owner-full-control
http://docs.amazonwebservices.com/AmazonS3/latest/API/mpUploadInitiate.html

Resources