Last active
October 18, 2020 05:00
-
-
Save h-hub/73e7a0932bf9e452e298df1b8be293d8 to your computer and use it in GitHub Desktop.
Revisions
-
h-hub revised this gist
Oct 18, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ public String uploadImage(MultipartFile image, String bucketName) { try { bimg = ImageIO.read(imageFile); } catch (IOException e) { throw new FileUploadException("Unable to read image."); } AmazonS3 s3client = AmazonS3ClientBuilder.standard().withRegion("ap-southeast-1").build(); -
h-hub revised this gist
Oct 18, 2020 . 1 changed file with 32 additions and 32 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,34 +1,34 @@ public String uploadImage(MultipartFile image, String bucketName) { File imageFile; try { imageFile = convertMultiPartToFile(image); } catch (IOException e) { throw new FileUploadException("Unable to convert input stream to file."); } BufferedImage bimg = null; try { bimg = ImageIO.read(imageFile); } catch (IOException e) { throw new FileUploadException("AvatarImgValidator: Unable to read image."); } AmazonS3 s3client = AmazonS3ClientBuilder.standard().withRegion("ap-southeast-1").build(); TransferManager xfer_mgr = TransferManagerBuilder.standard().withS3Client(s3client).build(); String fileName = generateFileName(image); try { Upload xfer = xfer_mgr.upload(new PutObjectRequest(bucketName, fileName, imageFile) .withCannedAcl(CannedAccessControlList.PublicRead)); xfer.waitForCompletion(); } catch (AmazonServiceException | InterruptedException e) { throw new FileUploadException("AWS Error or Upload was interrupted"); } xfer_mgr.shutdownNow(); return "https://"+bucketName+".s3-ap-southeast-1.amazonaws.com/"+fileName; } -
h-hub created this gist
Oct 17, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ public String uploadImage(MultipartFile image, String bucketName) { File imageFile; try { imageFile = convertMultiPartToFile(image); } catch (IOException e) { throw new FileUploadException("Unable to convert input stream to file."); } BufferedImage bimg = null; try { bimg = ImageIO.read(imageFile); } catch (IOException e) { throw new FileUploadException("AvatarImgValidator: Unable to read image."); } AmazonS3 s3client = AmazonS3ClientBuilder.standard().withRegion("ap-southeast-1").build(); TransferManager xfer_mgr = TransferManagerBuilder.standard().withS3Client(s3client).build(); String fileName = generateFileName(image); try { Upload xfer = xfer_mgr.upload(new PutObjectRequest(bucketName, fileName, imageFile) .withCannedAcl(CannedAccessControlList.PublicRead)); xfer.waitForCompletion(); } catch (AmazonServiceException | InterruptedException e) { throw new FileUploadException("AWS Error or Upload was interrupted"); } xfer_mgr.shutdownNow(); return "https://"+bucketName+".s3-ap-southeast-1.amazonaws.com/"+fileName; }