try {
Long contentLength = Long.valueOf(saveFile.getBytes().length);
AmazonS3 client = new AmazonS3Client(new BasicAWSCredentials(awsAccessKey, awsSecretKey));
/* ObjectMetadata meta = new ObjectMetadata();
meta.setContentLength(contentLength);
meta.setContentType(contentType);
client.putObject(bucket, saveFile, in, meta);
client.setObjectAcl(bucket, saveFile, CannedAccessControlList.PublicRead); */
GeneratePresignedUrlRequest imgURL = new GeneratePresignedUrlRequest(bucket, saveFile);
destFile = client.generatePresignedUrl(imgURL).toString();
} catch (Exception ex) {
System.out.println(ex);
}
I was trying to upload a photo into Amazon-S3, and it said "Data read has a different length than the expected". Even though I could avoid this error by changing
meta.setContentLength(saveFile.getBytes().length);
But it is still upload a damaged/corrupted image.
Aucun commentaire:
Enregistrer un commentaire