Amazon S3: How to display custom message instead of access denied 403 - ruby-on-rails

I am trying to access the uploaded files on the Amazon s3 bucket using the Rails application. When I click on the specific link, getting following error.
This XML file does not appear to have any style information associated with it. The document tree is shown below. <Error>
<Code>AccessDenied</Code>
<Message>Request has expired</Message>
<X-Amz-Expires>600</X-Amz-Expires>
<Expires>2016-07-20T22:22:58Z</Expires>
<ServerTime>2016-07-20T22:33:21Z</ServerTime>
<RequestId>461898B9DD2599A6</RequestId>
<HostId>
jAarpDNUJn+SygprDBXP/EnI9vN5sAR2OUqXSQ7UwsIXSAB6HR9OoYpmd3RXmxXv9AlZG+wsL8s=
</HostId>
</Error>
How to display custom error message instead of "Access Denied" page?

Related

Uploading a large attachment using Microsoft Graph

I am trying to upload a large (> 4mb) attachment to an existing message in Office 365. I am following these instructions: https://learn.microsoft.com/en-us/graph/outlook-large-attachments?tabs=http
I have successfully created the upload session, and obtained a uploadUrl value that looks legitimate, it roughly matches the example in the documentation. Then I start my PUT to this url, for the first byte range that I've selected. I'm sure I'm setting the Content-Type, Content-Length and Contact-Range headers correctly. My problem is that I get http 401 (Unauthorized) in response. The error header returned is "The audience claim value is invalid for current resource..." and it regurgitates my url and it looks intact.
My theory is that I need to add another API permission to my application. I already have mail read.write, and that allows me to create a < 4mb attachment. If I need another permission, which one? Or do I have some other problem?
According to this documentation page on Resumable Uploads, you'll need any of Files.ReadWrite, Files.ReadWrite.All or Sites.ReadWrite.All permissions for a Delegated Work account.
If you're using an Application token, then you need Sites.ReadWrite.All permission.
What were the permissions you were missing that you had to add out of interest? Was the docs clear from our perspective? I can see the Resumable file upload permissions is specific to SharePoint and can use "Files.ReadWrite, Files.ReadWrite.All, Sites.ReadWrite.All".
For mail message you'd need Mail.ReadWrite as per this doc for large file upload https://learn.microsoft.com/en-us/graph/api/message-post-attachments?view=graph-rest-1.0&tabs=http
I've created a feedback item on the doc to get this updated. https://github.com/microsoftgraph/microsoft-graph-docs/issues/6817

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

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.

Amazon S3 file request error

I am currently attempting to implement Amazon S3 into my rails application but am walking into an issue.
The gems i am using is CarrierWave and Fog.
This is the error i get when i try visit a file/image url.
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>42B0F41E7EF92ACC</RequestId>
<HostId>ESYXvkVKxnsu32LjfcsiErZ27IK44ItREPB68sBBHXqWHtzkN9fnc04oj8IzCEFg</HostId>
</Error>
This is the url my app is serving to view the image
https://vapenz-images.s3.amazonaws.com/uploads/product_image/image/2/Capture.PNG?AWSAccessKeyId=AKIAIEWRNU2VPG5SF7XQ&Signature=GcjA%2Bx46Q9wU%2BuaffhfCTLbLuAY%3D&Expires=1414545697
And here is a picture of the permissions.
My rails app currently can upload a image to s3 but it cant view them, i am quite lost.
Thanks for the help!

Cloudfront + S3 permissions

Some background. I'm using Rails + Carrierwave + S3 + Cloudfront.
I have a bucket and in the bucket there are many files. All the files are public. There is one file in particular. I can go to it on the S3 Console, select it, click on properties, and click on the link. It's a photo, so the photo will appear. I'm assuming that because I can do this, the photo has the correct public permissions.
I have a Cloudfront distribution pointing to this bucket. The Restrict Bucket Access is set to NO.
When I try to look at the photo through Cloudfront I get the error:
<Error>
<script/>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>blah</RequestId>
<HostId>
blahblahblah
</HostId>
</Error>
This is driving me absolutely bonkers. If anyone has any suggestions, I'd greatly appreciate it!

Resources