Heroku app not pulling S3 images on other machines - ruby-on-rails

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

Related

How to map already uploaded s3 image with ActiveStorage

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

AWS Cognito Authentication + AWS Mobile Client + API Gateway + S3 Bucket

I built a login screen for my app using AWSCognitoAuth, exactly like in one of the provided examples (https://github.com/awslabs/aws-sdk-ios-samples/tree/master/CognitoAuth-Sample). This works fine - it shows the login screen in an instance of SFSafariViewController where the user just logs in using regular username + passwort, or through Facebook or Google. So after this authentication, I get the access and refresh tokens which I can then use for fetching data from my API, which is routed through AWS API Gateway. The corresponding AWS API Gateway routes are configured to use "User Pools" authorization, instead of "IAM".
But now I need to download some files from a S3 bucket, which is not public. So what needs to be done, is to get temporary AWS Credentials and access the bucket using them. The AWSMobileClient library together with the S3 Transfer Utility are able to do that. But my problem is, I don't know how to tell the AWSMobileClient about the fact, that the user has now signed in .AWSMobileClient is initialized in the appDelegate's didFinishLaunching:withOptions like this:
let serviceConfiguration = AWSServiceConfiguration(
region: .EUWest1,
credentialsProvider: AWSMobileClient.sharedInstance().getCredentialsProvider()
)
//create a pool
let configuration = AWSCognitoIdentityUserPoolConfiguration.init(clientId: CognitoIdentityUserPoolAppClientId, clientSecret: CognitoIdentityUserPoolAppClientSecret, poolId: CognitoIdentityUserPoolId)
AWSCognitoIdentityUserPool.register(with: serviceConfiguration, userPoolConfiguration: configuration, forKey: AWSCognitoUserPoolsSignInProviderKey)
AWSServiceManager.default().defaultServiceConfiguration = serviceConfiguration
AWSFacebookSignInProvider.sharedInstance().setPermissions(["public_profile", "email"])
AWSSignInManager.sharedInstance().register(signInProvider: AWSFacebookSignInProvider.sharedInstance())
return AWSMobileClient.sharedInstance().interceptApplication(
application,
didFinishLaunchingWithOptions: launchOptions)
The thing is, when I completely close the app after doing the AWSCognitoAuth signin and reopen it, the AWSMobileClient somehow finds the session and the credentials are fetched properly and the file from the bucket gets loaded. But I need to somehow trigger this manually after the user signs in, I cannot force the user to quit and reopen the app, not in 2018... I have been debugging this now for a long time and was digging through the AWSMobileClient framework, trying to find how to hook those two together, but with no success. How can I do it?
But now I need to download some files from a S3 bucket, which is not
public. So what needs to be done, is to get temporary AWS Credentials
and access the bucket using them. The AWSMobileClient library together
with the S3 Transfer Utility are able to do that. But my problem is, I
don't know how to tell the AWSMobileClient about the fact, that the
user has now signed in .AWSMobileClient is initialized in the
appDelegate's didFinishLaunching:withOptions
Did you already try to use Pre-signed url? It is meant to cover your requirements. It allows temporary access to aws resources, in your case get access on S3 bucket.
You have samples using iOS sdk here, check the S3TransferUtility-Sample.
S3TransferUtility-Sample (Swift, Objective-C). This is a sample mobile
application that demonstrates how to use the Amazon S3 PreSigned URL
Builder to download / upload files in background. Involved AWS
Services are:
Amazon S3 Amazon
Cognito Identity
Hope it helps!

403 Forbidden Error for accessing images on google cloud bucket after transferred from one bucket to another

Actually I am using google cloud bucket for image upload in my rails app. I am using paper clip for image upload. I have used bucket name "abcd-old". I uploaded some of the images through app. It was working fine. But as of now I transffered the content of "abcd-old" bucket to new bucket "abcd-new". Also set the same permission as it was for old one. But now images are broken in the app. it shows "403 forbidden error". If I upload new image that will work. But old I mean transffered images are broken. Please help me on this.
This is the error I am getting
<Error>
<Code>AccessDenied</Code>
<Message>Access denied.</Message>
<Details>
Anonymous users does not have storage.objects.list access to bucket abcd-new.
</Details>
</Error>
We can resolve this issue by command line
gsutil -m acl -r set public-read gs://abcd-new
Please go through this link for more details http://tekhoow.blogspot.in/2015/12/soving-accessdenied-on-google-cloud.html

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.

Resources