403 Forbidden Release on Amazon S3

I use Amazon S3 to host user images. Although I have determined that they are all publicly available (this means that I can access images at my URLs in Chrome / Firefox / IE), I get a Forbidden 403 exception in my code. This is a thumbnail handler (C #, ASP.NET)

string file = context.Request.QueryString[IMG_PARAM].Trim().ToLower().Replace("\\", "/"); if (file.StartsWith("http") || file.StartsWith("https")) { using (System.Drawing.Image im = System.Drawing.Image.FromStream(WebRequest.Create(file).GetResponse().GetResponseStream())) using (System.Drawing.Image tn = this.CreateThumbnail(im)) { tn.Save(context.Response.OutputStream, this._formatType); } } 

The exception comes from this part:

 WebRequest.Create(file).GetResponse().GetResponseStream() 

This is very strange for me, if something is wrong with the ACL or permissions, why do I see images with a browser? Any help would be greatly appreciated.

+4
source share
3 answers

Found! After much research, I found it because of the URL strings that are CASE SENSITIVE. Turns out I had .toLower () somewhere:

 string file = context.Request.QueryString[IMG_PARAM].Trim().ToLower().Replace("\\", "/"); 

After removing .toLower (), the problem will be resolved.

+3
source

I found that you also get this error if you access Cloudfront CDN resources using CNAME, but do not add these CNAMES to distribution settings in the AWS management console.

EG:

 cdn.yourdomain.com/js/your_script.js rather than: abc12345.cloudfront.net/js/your_script.js 
+2
source

I had the same problem. This can also happen if you do not specify the root file option when setting up your Cloudfront distribution.

When I install my root file in index.html, everything works beautifully.

0
source

Source: https://habr.com/ru/post/1395215/


All Articles