public void upload(List<CommonsMultipartFile> fileUpload) {
for(CommonsMultipartFile file : fileUpload)
{
try
{
String contentType = file.getContentType();
String newName = generateFileKey(file);
AmazonS3UploadRequest uploadRequest = new AmazonS3UploadRequest.Builder()
.bucket(bucket)
.contentType(contentType)
.newResourceName(newName)
.resourceStream(file.getInputStream(), Long.valueOf(file.getBytes().length))
.build();
uploadToS3(uploadRequest);
}
catch (Exception e)
{
LOG.error("Error while uploading files to s3: ", e);
throw new ServiceRuntimeException("Error writing file to s3 bucket");
}
}
}
public String uploadToS3(AmazonS3UploadRequest uploadRequest) {
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(uploadRequest.getResourceLength());
objectMetadata.setContentType(uploadRequest.getContentType());
Upload upload = transferManager.upload(uploadRequest.getBucket(), uploadRequest.getNewResourceName(), uploadRequest.getResourceStream(), objectMetadata);
}
我正在将 pdf 文件上传到亚马逊 S3 存储桶,所有文件均已成功上传,但大文件(15 页 pdf 等)为空。Amazon transferManager - 正在通过 spring 注入。Amazon 凭证是从 TansferManager 中的 .property 文件注入的。注意:.png/.jpeg 文件也被上传为空文件。嗯,我有点困惑......发生了什么。需要一些输入。提前致谢。