我是 Dropwizard 的新手。我想在我的项目中实施 AWS S3 File upload 服务。
我没有通过dropwizard获得任何在AWS S3上传文件的教程。
我在 pom.xml
中添加了以下依赖项 <dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.9.28.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.17</version>
</dependency>
我已在应用程序类的run()方法中注册 MultiPartfeature.class 作为 -
environment.jersey().register(MultiPartFeature.class);
然后在资源类定义的方法中为 -
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/updateProfilePicture")
public String updateProfile(@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition contentDispositionHeader) throws Exception {
String url = "";
AmazonS3 s3client = new AmazonS3Client(new BasicAWSCredentials("MY-ACCESS-KEY", "MY-SECRET_KEY"));
try {
File file = new File(contentDispositionHeader.getFileName());
PutObjectResult putObjectResult = s3client.putObject(new PutObjectRequest("BUCKET-NAME", s3SourceFactory.getSecretAccessKey(), fileInputStream, new ObjectMetadata()));
} catch (AmazonServiceException ase) {
ase.printStackTrace();
} catch (AmazonClientException ace) {
ace.printStackTrace();
}
return url;
}
但是在运行时它会显示以下日志 -
com.amazonaws.services.s3.AmazonS3Client: No content length specified for stream data. Stream contents will be buffered in memory and could result in out of memory errors.
如何获取上传文件的网址?如何检查文件是通过编码上传的?我错过了什么吗?有没有人对此有任何想法。如果有任何关于dropwizard的教程,那将会有所帮助。
提前致谢
答案 0 :(得分:1)
如果访问密钥和密钥是正确的。我的猜测是针对S3存储桶权限,一旦你在aws控制台上转到你的s3存储桶,在右上方你会发现&#34;属性&#34; ,一旦你打开,你将拥有权限,确保你在那里为你的服务器提供了一个条目。