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