PreventOverwrite

This commit is contained in:
2026-05-28 21:04:09 +02:00
parent 94bf9c61a3
commit d35e8eb5f7
2 changed files with 7 additions and 5 deletions
+2 -4
View File
@@ -4,12 +4,11 @@ namespace Musify.Application.Contracts
{
Task<Stream> GetFileAsync(string bucket, string key, CancellationToken cancellationToken);
// Returns null if the object does not exist
Task<ObjectMetaData?> HeadObjectAsync(string bucket, string key, CancellationToken cancellationToken);
Task<string> GetUrlAsync(string bucket, string key, TimeSpan ExpirationTime, CancellationToken cancellationToken);
Task<string> GetUploadUrlAsync(string bucket, string key, string contentType, TimeSpan expirationTime, CancellationToken cancellationToken);
Task<string> GetUploadUrlAsync(string bucket, string key, string contentType, TimeSpan expirationTime, CancellationToken cancellationToken, bool preventOverwrite = true);
Task UploadFileAsync(string filePath, string bucket, string key, CancellationToken cancellationToken);
@@ -23,8 +22,7 @@ namespace Musify.Application.Contracts
CancellationToken cancellationToken);
Task RemoveFolderAsync(string bucket, string folderKey, CancellationToken cancellationToken);
// Returns (key, lastModifiedUtc) for all objects under the given prefix
IAsyncEnumerable<(string Key, DateTime LastModifiedUtc)> ListObjectsAsync(string bucket, string prefix, CancellationToken cancellationToken);
}
}
+5 -1
View File
@@ -55,7 +55,8 @@ namespace Musify.Infrastructure.Services
string key,
string contentType,
TimeSpan expirationTime,
CancellationToken cancellationToken)
CancellationToken cancellationToken,
bool preventOverwrite = true)
{
var request = new GetPreSignedUrlRequest
{
@@ -67,6 +68,9 @@ namespace Musify.Infrastructure.Services
ContentType = contentType
};
if (preventOverwrite)
request.Headers["If-None-Match"] = "*";
logger.LogDebug("Generating pre-signed upload URL for {Bucket}/{Key}", bucket, key);
return await amazonS3.GetPreSignedURLAsync(request);
}