AmazonClientException: Data read has a different length than the expected

前端 未结 4 1779
礼貌的吻别
礼貌的吻别 2020-12-19 09:56

1.When I am using AmazonS3Client to upload file on amazon s3 file store. 2.when I am trying to upload multiple files at a time it gives exceptions: but same file multiple th

4条回答
  •  难免孤独
    2020-12-19 10:18

    ...
    byte[] f = IOUtils.toByteArray(inputStream); // This reads all bytes of the input stream
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(f.length);
    metadata.setContentType(contentType); //Content type of the uploaded file
    metadata.setHeader("filename", fileName);
    s3.putObject(bucketName, key, new ByteArrayInputStream(f), metadata); // Here we create a new ByteArrayInputStream so S3 client get happy.
    

提交回复
热议问题