1

I have these two types of method to get the file in S3.

//method 1
var client = new AmazonS3Client();

            var request = new GetPreSignedUrlRequest()
            {
                BucketName = BucketName,
                Key = fileName,
                Expires = DateTime.UtcNow.AddSeconds(300),
            };

            var presignedUrlResponse = client.GetPreSignedURL(request);
            return presignedUrlResponse;
//method 2
var client = new AmazonS3Client();
            var request = new GetPreSignedUrlRequest()
            {
                BucketName = BucketName,
                Key = fileName,
            };
            var file = await client.GetObjectAsync(BucketName, fileName);
            return File(file.ResponseStream, file.Headers.ContentType);

In my method 1 by using GetPreSignedURL it saves the name of the region in the path of the photo and I don't want that, I need it to save without, because then I can't open the photo in the browser. Example: https://service-manager-estagio.s3.sa-east-1.amazonaws.com/urlphoto I want to save without this sa-east-1

In my method 2 on the return File line I can't use this File, the message is that I can't use it as a method

I need help using method 1 and saving without the region name or using method 2 with this File. But if anyone knows another way to do this GET is valid too. Thanks!!

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • Sorted out! Method 1, I was re-creating the S3 Client, I just deleted it and used what I had created up there and as dependency injection. ``` var request = new GetPreSignedUrlRequest() { BucketName = BucketName, Key = fileName, Expires = DateTime.UtcNow.AddMinutes(5), }; return _awsS3Client.GetPreSignedURL(request); ``` – MICHEL BALARIN CLARO Sep 17 '22 at 23:48

0 Answers0