6

I m using amazon sdk for .net i have uploaded a file in folder of my bucket , now i want to get the url of that 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 this is returning url with key , exipration date and signature but infact i want to get the url without them , there is no other method to get the url

**Things i tried **

i search and found that i have to change permission of my file

i have change the permission of file while uploading

request.CannedACL = S3CannedACL.PublicRead;

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

it work when i remove keyid ,expire and signature but how can i get url with out it , or do i have to do it manually

Ahtesham ul haq
  • 319
  • 1
  • 5
  • 14

2 Answers2

1

This is by design. If you know the bucket name and the key then you have everything you need to construct the URL. As an example, here bucketname is yourbucketname and the key is this/is/your/key.jpg.

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

Hope that helps!

1

I just browsed their documentation and was not able to find a method to return an absolute url. However, I really believe there is one that I could not see. For now, you can solve your problem by extracting an absolute url from the result you have:

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 it helps :)

Coke
  • 965
  • 2
  • 9
  • 22