Skip to content

Expose .abort() method in S3OutputStream for cancelling partially completed uploads #1199

Closed
@zhemaituk

Description

@zhemaituk

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:

  1. User uploads large file via UI
  2. Backend accepts the file, starts validating file and proxy writes it to S3 for storage
  3. 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

  1. Use reflection to call InMemoryBufferingS3OutputStream#abortMultiPartUpload
  2. Delete the file if upload (partially) fails. Does not work that well on versioned buckets/objects.
  3. Copy-paste InMemoryBufferingS3OutputStream and expose abort method
    None of the alternatives are appealing.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: s3S3 integration related issuetype: enhancementSmaller enhancement in existing integration

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions