简体   繁体   English

使用 Java 将 AWS 文件上传到 S3

[英]AWS File Upload to S3 with Java

I am trying to upload files into my S3 bucket using AWS Lambda in Java and i'm having some issues.我正在尝试使用 Java 中的AWS Lambda将文件上传到我的S3 bucket中,但我遇到了一些问题。

I am using APIGatewayProxyRequestEvent in my AWS Lambda function to get my file upload from Postman .我在我的AWS Lambda函数中使用APIGatewayProxyRequestEventPostman获取我的文件上传。

request.getBody() method of this event gives me a String representation of the image file whereas the S3.putObject takes as input an InputStream of the file to be uploaded.此事件的request.getBody()方法为我提供了图像文件的字符串表示,而S3.putObject将要上传的文件的 InputStream 作为输入。

How can I feed in request.getBody() to the S3.putObject() method in my Lambda code to make the File Upload work?如何将request.getBody()给 Lambda 代码中的S3.putObject()方法以使文件上传工作?

1) You may create a File and using FileWriter you may write the request.getBody() into it. 1) 您可以创建一个 File 并使用 FileWriter 您可以将 request.getBody() 写入其中。 2) You can go with PutObjectRequest object and put file created in Step1 into it. 2)您可以使用 PutObjectRequest 对象并将在 Step1 中创建的文件放入其中。 3) s3Client.putObject(PutObjectRequest) will help you to put object to s3 3) s3Client.putObject(PutObjectRequest) 将帮助您将对象放入 s3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM