Closed
Description
Type: Feature
Is your feature request related to a problem? Please describe.
If writing a file through S3OutputStream has started - there is no possibility to abort the upload.
My scenario:
- User uploads large file via UI
- Backend accepts the file, starts validating file and proxy writes it to S3 for storage
- Something goes wrong (user abandons the upload, file turns out invalid, etc.)
Sample code:
try (
S3OutputStream s3Stream = inMemoryBufferingS3StreamProvider.create(uploadLocation,
ObjectMetadata.builder()
.contentType("text/csv")
.build());
CSVWriter writer = new CSVWriter(new OutputStreamWriter(s3Stream))
) {
try {
String[] headers = reader.readNext();
validateHeaders(headers);
writer.writeNext(headers);
String[] row;
while ((row = reader.readNext()) != null) {
// Further data validation is done at this stage.
writer.writeNext(row);
}
} catch (CsvValidationException|IOException e) {
// TODO: Abort the upload?!
// TODO: s3Stream.abort();
}
}
Describe the solution you'd like
New method S3OutputStream#abort
which can be called if the stream is not closed yet.
Describe alternatives you've considered
- Use reflection to call
InMemoryBufferingS3OutputStream#abortMultiPartUpload
- Delete the file if upload (partially) fails. Does not work that well on versioned buckets/objects.
- Copy-paste InMemoryBufferingS3OutputStream and expose
abort
method
None of the alternatives are appealing.
Additional context