我有这段代码可以在本地主机上完美运行(文件正确上传到aws s3存储桶),但是当我将应用程序上传到aws lambda时,文件以损坏的形式上传到s3(显示空白/奇怪字节字符)。有人知道我在这里做错了吗?如果我上传txt文件,事情不会中断,所以我很困惑。
@RequestMapping(value = "/uploadNew", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA )
public ResponseEntity uploadNew( @RequestParam("files") MultipartFile file) throws IOException {
//put the object into the bucket
ObjectMetadata data = new ObjectMetadata();
data.setContentType(file.getContentType());
data.setContentLength(file.getSize());
BasicAWSCredentials awsCreds = new BasicAWSCredentials("xxxxx", "xxxxx");
AmazonS3 s3client = AmazonS3ClientBuilder.standard().withRegion(Regions.US_EAST_1).withCredentials(new AWSStaticCredentialsProvider(awsCreds)).build();
PutObjectResult objectResult = s3client.putObject("xxxxx", file.getOriginalFilename(), file.getInputStream(), data);