繁体   English   中英

AWS S3文件上传与dropwizard集成?

[英]AWS S3 file upload integration with dropwizard?

我是Dropwizard的新手 我想在我的项目中实现AWS S3 File上传服务。

我没有得到任何通过dropwizard在AWS S3上上传文件的教程。

我在pom.xml中添加了以下dependecies

    <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>

我在Application类的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,它将是有帮助的。

提前致谢

如果访问密钥和密钥是正确的。 我的猜测是针对S3存储桶权限,一旦你在aws控制台上转到你的s3存储桶,你会找到“属性”,一旦打开你将拥有权限,确保你在那里为你的服务器提供了一个条目。

暂无
暂无

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

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