简体   繁体   English

AWS S3文件上传与dropwizard集成?

[英]AWS S3 file upload integration with dropwizard?

I am new to Dropwizard . 我是Dropwizard的新手 I want to implement AWS S3 File upload service in my project. 我想在我的项目中实现AWS S3 File上传服务。

I am not getting any tutorial to upload file on AWS S3 through dropwizard. 我没有得到任何通过dropwizard在AWS S3上上传文件的教程。

I have added following dependecies in pom.xml 我在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>

I have registered MultiPartfeature.class in Application class's run() method as - 我在Application类的run()方法中注册了MultiPartfeature.class -

environment.jersey().register(MultiPartFeature.class);

Then in resource class defined method as - 然后在资源类中定义方法为 -

@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;
}

But at run-time it shows the following log - 但在运行时它显示以下日志 -

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.

How can I get the url of uploaded file? 如何获取上传文件的网址? How to check file is uploaded through coding? 如何检查文件是通过编码上传的? Am I missing anything? 我错过了什么吗? Does anybody have any idea about this. 有没有人对此有任何想法。 If there any tutorial available with dropwizard, it will be helpful. 如果有任何教程可用dropwizard,它将是有帮助的。

Thanks in advance 提前致谢

If the access key and secret key are correct. 如果访问密钥和密钥是正确的。 My guess is towards the S3 bucket permissions, once you go to your s3 bucket on aws console, to the right top you will find "properties" , once you open that you will have permissions make sure you gave an entry for your server there. 我的猜测是针对S3存储桶权限,一旦你在aws控制台上转到你的s3存储桶,你会找到“属性”,一旦打开你将拥有权限,确保你在那里为你的服务器提供了一个条目。

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

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