AmazonS3 putObject with InputStream length example

前端 未结 8 2048
梦如初夏
梦如初夏 2020-12-04 07:36

I am uploading a file to S3 using Java - this is what I got so far:

AmazonS3 s3 = new AmazonS3Client(new BasicAWSCredentials(\"XX\",\"YY\"));

List

        
8条回答
  •  粉色の甜心
    2020-12-04 08:04

    While writing to S3, you need to specify the length of S3 object to be sure that there are no out of memory errors.

    Using IOUtils.toByteArray(stream) is also prone to OOM errors because this is backed by ByteArrayOutputStream

    So, the best option is to first write the inputstream to a temp file on local disk and then use that file to write to S3 by specifying the length of temp file.

提交回复
热议问题