How to disable saving image in project structure ?
Hi,
I working with Java Spring Boot application, and when I save image on Cloudinary, image appearing in project structure like file. So if I deploy this solution my project can reach thousand megabytes...
Look at the picture:
Is this default behavior or it's my mistake in code ?
-
Hi Horeca,
How does your application work with the uploaded images, and how are you calling Cloudinary's APIs?
Are you receiving uploaded files on the server side from a user-upload and storing them temporarily in your application server's storage before uploading them to Cloudinary? If so, is there something in your code to remove those files afterward?
Thanks,Stephen
0 -
Hi Stephen,
Here is the method for upload image on Cloudinary:// Method for saving:
File file = this.convertMultipartFileToFile(multipartFile);
Cloudinary cloudinary = new Cloudinary(CONFIG);
Map result = cloudinary.uploader().upload(file, ObjectUtils.emptyMap());
String url = (String) result.get("secure_url");
person.setImageURL(url);
...//Method for convert Multipart File to File:
public File convertMultipartFileToFile(MultipartFile multipartFile) {
File convFile = new File(multipartFile.getOriginalFilename());
try {
convFile.createNewFile();
FileOutputStream fos = new FileOutputStream(convFile);
fos.write(multipartFile.getBytes());
fos.close();
} catch (IOException e) {
}
return convFile;In Controller I catching file from request:
@RequestParam(name = "file") MultipartFile multipartFile
0 -
Hi Horeca,
Thanks for sharing your code.
When using FileOutputStream.write(), the file data may get cached and saved to your disk. In order to avoid this, you should make sure to delete the file after closing the FileOutputStream.
Let us know if this solves your issue,
Best,
Michal
0 -
Hi Michal,
Thank you for the answer that's solve my problem!
All best,
Horeca
0 -
Great! Thanks for the update.
0
Post is closed for comments.
Comments
5 comments