AmazonS3 putObject with InputStream length example

前端 未结 8 2045
梦如初夏
梦如初夏 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 07:57

    Because the original question was never answered, and I had to run into this same problem, the solution for the MD5 problem is that S3 doesn't want the Hex encoded MD5 string we normally think about.

    Instead, I had to do this.

    // content is a passed in InputStream
    byte[] resultByte = DigestUtils.md5(content);
    String streamMD5 = new String(Base64.encodeBase64(resultByte));
    metaData.setContentMD5(streamMD5);
    

    Essentially what they want for the MD5 value is the Base64 encoded raw MD5 byte-array, not the Hex string. When I switched to this it started working great for me.

提交回复
热议问题