Get unsigned amazon web service urls in c #

I use amazon sdk for .net I uploaded the file to my bucket folder, now I want to get the URL of this file using this code

GetPreSignedUrlRequest request = new GetPreSignedUrlRequest(); request.BucketName = "my-new-bucket2"; request.Key = "Images/Tulips.jpg"; request.Expires = DateTime.Now.AddHours(1); request.Protocol = Protocol.HTTP; string url = s3.GetPreSignedURL(request); 

but it returns url with key, expiration date and signature, but infact I want to get url without them, there is no other method to get url

** Things I've tried **

i and found that I need to change the resolution of my file

I change the file resolution on boot

 request.CannedACL = S3CannedACL.PublicRead; 

but this returns the same URL http://my-new-bucket2.s3-us-west-2.amazonaws.com/Images/Tulips.jpg?AWSAccessKeyId=xxxxxxxxxxxx&Expires=1432715743&Signature=xxxxxxxxxxx%3D

it works when I delete the keyid, the signature expires but how can I get the url with this, or should I do it manually

+6
source share
2 answers

This is by design. If you know the name of the bucket and the key, then you have everything you need to create the URL. For example, here bucketname has the value yourbucketname , and the key is this/is/your/key.jpg .

https://yourbucketname.s3.amazonaws.com/this/is/your/key.jpg

Hope this helps!

0
source

I just looked through their documentation and could not find a method for returning an absolute URL. However, I really believe that there is one that I could not see. So far, you can solve your problem by extracting the absolute URL from the result:

 GetPreSignedUrlRequest request = new GetPreSignedUrlRequest(); request.BucketName = "my-new-bucket2"; request.Key = "Images/Tulips.jpg"; request.Expires = DateTime.Now.AddHours(1); request.Protocol = Protocol.HTTP; string url = s3.GetPreSignedURL(request); index = url.IndexOf("?"); if (index > 0) string absUrl = url.Substring(0, index); 

Hope this helps :)

0
source

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


All Articles