Created
November 21, 2014 11:14
-
-
Save rafayali/fe89a946b00b9b7e78f7 to your computer and use it in GitHub Desktop.
Uploads buffered image to amazon S3 server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void uploadBufferedImageToServer(BufferedImage image, String fileName, String imageType) throws IOException, NullPointerException { | |
ByteArrayOutputStream outstream = new ByteArrayOutputStream(); | |
ImageIO.write(image, "png", outstream); | |
byte[] buffer = outstream.toByteArray(); | |
InputStream is = new ByteArrayInputStream(buffer); | |
ObjectMetadata meta = new ObjectMetadata(); | |
meta.setContentType("image/" + imageType); | |
meta.setContentLength(buffer.length); | |
AmazonS3 s3client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey)); | |
s3client.putObject(new PutObjectRequest(awsBucketName, fileName, is, meta).withCannedAcl(CannedAccessControlList.PublicRead)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment