Darlyn
Darlyn

Reputation: 4938

AWS S3 multipart upload with raw bytes instead of File

I am trying to create multipart upload, however i am recieving raw data, not file, and in examples in documentation multipart request requires File, not data e.g

UploadPartRequest uploadRequest = new UploadPartRequest()
        .withBucketName(bucketName)
        .withKey(key)
        .withUploadId(initResponse.getUploadId())
        .withPartNumber(part) // parts start with 1
        .withFileOffset(filePosition)
        .withFile(filePath.toFile())
        .withPartSize(partSize);
UploadPartResult uploadPartResult = amazonS3.uploadPart(uploadRequest);
partETags.add(uploadPartResult.getPartETag());

Is there any way how to pot raw byes into the UploadPartRquest? Something like

byte[] data = getData();
UploadPartRequest uploadRequest = new UploadPartRequest()
        .withBucketName(bucketName)
        .withKey(key)
        .withUploadId(initResponse.getUploadId())
        .withPartNumber(part) // parts start with 1
        .withFileOffset(filePosition)
        .withData(data)
        .withPartSize(partSize);
UploadPartResult uploadPartResult = amazonS3.uploadPart(uploadRequest);
partETags.add(uploadPartResult.getPartETag());

Or am i stuck with creating temp file, sending it to request object and then deleting said file?

Thanks for help!

Upvotes: 0

Views: 1281

Answers (1)

Oliver Dain
Oliver Dain

Reputation: 9963

It looks like there's a withInputStream method and you can always create an InputStream from a byte array via ByteArrayInputStream. Combined I think that'll do what you want.

Upvotes: 1

Related Questions