From 0bd115eccb81fff150844b2e3053f1fff540b61e Mon Sep 17 00:00:00 2001 From: Aaron Po Date: Sun, 11 Oct 2026 23:08:59 -0400 Subject: [PATCH] Update S3FileStorageProvider.cs --- .../Services/S3FileStorageProvider.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/web/backend/Features/Features.PhotoUpload/Services/S3FileStorageProvider.cs b/web/backend/Features/Features.PhotoUpload/Services/S3FileStorageProvider.cs index bc5879b1..c52b1ad7 100644 --- a/web/backend/Features/Features.PhotoUpload/Services/S3FileStorageProvider.cs +++ b/web/backend/Features/Features.PhotoUpload/Services/S3FileStorageProvider.cs @@ -14,6 +14,7 @@ public class S3FileStorageProvider : IFileStorageProvider, IDisposable private readonly string _bucket; private readonly IAmazonS3 _client; private readonly IAmazonS3 _presignClient; + private readonly Protocol _presignProtocol; /// /// Initializes a new instance of the class, reading storage @@ -64,6 +65,14 @@ public class S3FileStorageProvider : IFileStorageProvider, IDisposable secretAccessKey, new AmazonS3Config { ServiceURL = publicUrl, ForcePathStyle = true } ); + + // GetPreSignedUrlRequest.Protocol defaults to HTTPS and ignores the ServiceURL scheme, so + // take the scheme from the endpoint the URL is signed against. + _presignProtocol = + Uri.TryCreate(publicUrl, UriKind.Absolute, out Uri? publicUri) + && publicUri.Scheme == Uri.UriSchemeHttp + ? Protocol.HTTP + : Protocol.HTTPS; } /// @@ -101,6 +110,7 @@ public class S3FileStorageProvider : IFileStorageProvider, IDisposable BucketName = _bucket, Key = key, Expires = DateTime.UtcNow.Add(expiresIn), + Protocol = _presignProtocol, }; return _presignClient.GetPreSignedURL(request);