I am new to Dropwizard. I want to implement AWS S3 File upload service in my project.
I am not getting any tutorial to upload file on AWS S3 through dropwizard.
I have added following dependecies in 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>
I have registered MultiPartfeature.class in Application class's run() method as -
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.
Thanks in advance