I have a form to upload image, so what I want is that whenever a user uploads any type of image (png/jpg etc) convert that image into jpg and save that image to storage from Multipart.
Asked
Active
Viewed 317 times
-3
-
See here: https://www.mkyong.com/java/convert-png-to-jpeg-image-file-in-java/ – Joe Taras Dec 04 '18 at 11:38
-
See also here: https://stackoverflow.com/questions/2290336/converting-png-into-jpeg – Joe Taras Dec 04 '18 at 11:38
-
I am uploading a file that is In MultipartFile format , I want to first change it into jpg format and than save it into storage . – john Dec 04 '18 at 12:02
-
Welcome to Stack Overflow. [First Google hit](https://spring.io/guides/gs/uploading-files/). Please review [ask]. – Jason Armstrong Dec 04 '18 at 12:28
1 Answers
0
I think you can have a response with this previous question :
File inputFile = new File("/fileOfYourForm.png");
File outputFile = new File("NewImage.jpg");
try (InputStream is = new FileInputStream(inputFile)) {
BufferedImage image = ImageIO.read(is);
try (OutputStream os = new FileOutputStream(outputFile)) {
ImageIO.write(image, "jpg", os);
} catch (Exception exp) {
exp.printStackTrace();
}
} catch (Exception exp) {
exp.printStackTrace();
}

Fizik26
- 753
- 2
- 10
- 25