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 manipulated productInputStream using a third-party library. Since I could not change the third-party library, I just performed the download 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 to my generateThumbnail method:
productInputStream.reset();
6006604
source share