How to disable saving image in project structure ?

Comments

5 comments

  • Avatar
    Stephen Doyle

    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
    Comment actions Permalink
  • Avatar
    Horeca

    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
    Comment actions Permalink
  • Avatar
    Michal Kuperman

    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
    Comment actions Permalink
  • Avatar
    Horeca

    Hi Michal,

    Thank you for the answer that's solve my problem!

    All best,

    Horeca

    0
    Comment actions Permalink
  • Avatar
    Michal Kuperman

    Great! Thanks for the update.

     

    0
    Comment actions Permalink

Please sign in to leave a comment.