An exception “The Content-MD5 you specified did not match what we received”

后端 未结 5 1577
谎友^
谎友^ 2021-01-17 17:14

I got an exception, I never got before when testing my application that uploads a file from ec2 to s3. The content is:

Exception in thread \"Thread-1\" com.a         


        
5条回答
  •  逝去的感伤
    2021-01-17 17:33

    I also ran into this error when I was doing something like this:

    InputStream productInputStream = convertImageFileToInputStream(file);
    
    InputStream thumbnailInputStream = generateThumbnail(productInputStream);
    
    String uploadedFileUrl = amazonS3Uploader.uploadToS3(BUCKET_PRODUCTS_IMAGES, productFilename, productInputStream);
    
    String uploadedThumbnailUrl = amazonS3Uploader.uploadToS3(BUCKET_PRODUCTS_IMAGES, productThumbnailFilename, thumbnailInputStream);
    

    The generateThumbnail method was manipulating the productInputStream using a third party library. Because I couldn't modify the third party library, I simply performed the upload first:

    InputStream productInputStream = convertImageFileToInputStream(file);
    
    // do this first... 
    String uploadedFileUrl = amazonS3Uploader.uploadToS3(BUCKET_PRODUCTS_IMAGES, productFilename, productInputStream);
    
    /// and then this...
    InputStream thumbnailInputStream = generateThumbnail(productInputStream);
    
    String uploadedThumbnailUrl = amazonS3Uploader.uploadToS3(BUCKET_PRODUCTS_IMAGES, productThumbnailFilename, thumbnailInputStream);
    

    ... and added this line inside my generateThumbnail method:

    productInputStream.reset();
    

提交回复
热议问题