Skip to content

Commit

Permalink
Bug fix on the S3OutputStream wrapper (#56)
Browse files Browse the repository at this point in the history
* Bug fix to properly upload files that are less than the buffer size
  • Loading branch information
millmanw authored Mar 16, 2022
1 parent d36549a commit acd7623
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package io.zulia.server.filestorage.io;

import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.AbortMultipartUploadRequest;
import software.amazon.awssdk.services.s3.model.CompleteMultipartUploadRequest;
import software.amazon.awssdk.services.s3.model.CompletedMultipartUpload;
import software.amazon.awssdk.services.s3.model.CompletedPart;
import software.amazon.awssdk.services.s3.model.CreateMultipartUploadRequest;
import software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.UploadPartRequest;
import software.amazon.awssdk.services.s3.model.UploadPartResponse;

import java.io.ByteArrayInputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.*;

/**
* OutputStream which wraps S3Client, with support for streaming large files directly to S3
*
Expand Down Expand Up @@ -141,8 +148,8 @@ public void close() {
this.s3Client.completeMultipartUpload(cmur);
}
else {
PutObjectRequest req = PutObjectRequest.builder().bucket(bucket).key(key).contentLength((long) this.buf.length).build();
s3Client.putObject(req, RequestBody.fromBytes(this.buf));
PutObjectRequest req = PutObjectRequest.builder().bucket(bucket).key(key).contentLength((long) this.position).build();
s3Client.putObject(req, RequestBody.fromInputStream(new ByteArrayInputStream(buf, 0, this.position), this.position));
}
}
}
Expand Down

0 comments on commit acd7623

Please sign in to comment.