mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-07-20 12:54:44 +02:00
Always abort multipart upload on exception
This commit is contained in:
@ -19,8 +19,7 @@ public static class Extensions
|
|||||||
RegionEndpoint = !string.IsNullOrEmpty(c.Region) ? RegionEndpoint.GetBySystemName(c.Region) : null,
|
RegionEndpoint = !string.IsNullOrEmpty(c.Region) ? RegionEndpoint.GetBySystemName(c.Region) : null,
|
||||||
ServiceURL = c.ServiceUrl?.ToString(),
|
ServiceURL = c.ServiceUrl?.ToString(),
|
||||||
UseHttp = c.ServiceUrl?.Scheme == "http",
|
UseHttp = c.ServiceUrl?.Scheme == "http",
|
||||||
ForcePathStyle = true,
|
ForcePathStyle = true
|
||||||
SignatureVersion = "4"
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,10 +165,12 @@ public class S3FileStore : StreamFileStore, IFileStore
|
|||||||
|
|
||||||
private async Task<PrivateVoidFile> IngressMultipart(IngressPayload payload, CancellationToken cts)
|
private async Task<PrivateVoidFile> IngressMultipart(IngressPayload payload, CancellationToken cts)
|
||||||
{
|
{
|
||||||
string? uploadId;
|
string? uploadId = null;
|
||||||
var cacheKey = $"s3:{_config.Name}:multipart-upload-id:{payload.Id}";
|
var cacheKey = $"s3:{_config.Name}:multipart-upload-id:{payload.Id}";
|
||||||
var partsCacheKey = $"s3:{_config.Name}:multipart-upload:{payload.Id}";
|
var partsCacheKey = $"s3:{_config.Name}:multipart-upload:{payload.Id}";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
if (payload.Segment == 1)
|
if (payload.Segment == 1)
|
||||||
{
|
{
|
||||||
var mStart = new InitiateMultipartUploadRequest()
|
var mStart = new InitiateMultipartUploadRequest()
|
||||||
@ -208,12 +210,6 @@ public class S3FileStore : StreamFileStore, IFileStore
|
|||||||
var bodyResponse = await _client.UploadPartAsync(mBody, cts);
|
var bodyResponse = await _client.UploadPartAsync(mBody, cts);
|
||||||
if (bodyResponse.HttpStatusCode != HttpStatusCode.OK)
|
if (bodyResponse.HttpStatusCode != HttpStatusCode.OK)
|
||||||
{
|
{
|
||||||
await _client.AbortMultipartUploadAsync(new()
|
|
||||||
{
|
|
||||||
BucketName = _config.BucketName,
|
|
||||||
UploadId = uploadId
|
|
||||||
}, cts);
|
|
||||||
|
|
||||||
throw new Exception("Upload aborted");
|
throw new Exception("Upload aborted");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,6 +242,22 @@ public class S3FileStore : StreamFileStore, IFileStore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return HandleCompletedUpload(payload, segmentLength);
|
return HandleCompletedUpload(payload, segmentLength);
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
if (uploadId != null)
|
||||||
|
{
|
||||||
|
await _client.AbortMultipartUploadAsync(new()
|
||||||
|
{
|
||||||
|
Key = payload.Id.ToString(),
|
||||||
|
BucketName = _config.BucketName,
|
||||||
|
UploadId = uploadId
|
||||||
|
}, cts);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user