Reputation: 5660
I am building an image server. There is a servlet which takes in an image and intention is to store image in Amazon S3.
Part filePart = request.getPart("file");
InputStream inputStream = filePart.getInputStream();
How to stream the contents to amazon s3, without downloading file to secondary storage ?
The Amazon S3 api is
System.out.println("Uploading a new object to S3 from a file\n");
File file = new File(uploadFileName);
s3client.putObject(new PutObjectRequest(
bucketName, keyName, file));
But this requires some file path to the local storage. How can I transfer the image from the servlet directly to S3 without storing it on disk ?
Upvotes: 0
Views: 1372
Reputation: 36
Yes, there is another api is put inputStream into S3 directly.
public PutObjectRequest(java.lang.String bucketName,
java.lang.String key,
java.io.InputStream input,
ObjectMetadata metadata)
Upvotes: 1