rafayali
11/21/2014 - 11:14 AM

Uploads buffered image to amazon S3 server

Uploads buffered image to amazon S3 server

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