View and release image file programmatically using Java web application

Hi,
I was not sure if opening a new thread or writing on the old one…
The problem I reported here on version 17.2 is happening in GroupDocs 19.11.
After using getDocumentInfo method from class ViewerHtmlHandler I cannot delete the file because it keeps it open.
Here is the code I used:

public static void main(String[] args) throws Exception{
    ViewerConfig config = new ViewerConfig();
    config.setEnableCaching(true);
    ViewerHtmlHandler viewerHandler = new ViewerHtmlHandler(config);
    viewerHandler.clearCache();
    
    String file = "C:\\Users\\Jorge Eduardo\\Desktop\\Infolluviaacida.jpg";
    
    DocumentInfoContainer info = viewerHandler.getDocumentInfo(file);
    
    System.out.println(info.getSize());
    
    Thread.sleep(30000);
    System.out.println("Finished!");
}

Can you confirm, please? Maybe I am missing something.
Thanks.

1 Like

@jorgeeflorez,

We cannot reproduce this issue using v19.11. Please see this screenshot.png (418.8 KB). We can delete.png (126.5 KB) the source file as application shows file size in console and terminates. However, you cannot delete the source file until application is terminated.

Hi atirtahir3, thanks for your reply.
I am not sure if I understood you correctly. I cannot delete the file while the application is running, to me that’s a problem. I need to delete after some time passed, the temporary files GroupDocs created and the file used for that as well. The application where I need to do that is a web application and cannot be stopped to perform deletion. If getDocumentInfo keeps the file open, how can I perform cleanup?

If I use version 19.8 I can delete the file while the program is still running (after the file size is printed and before “Finished!” is printed). I don’t know if this can be of help…

@jorgeeflorez,

Thanks for the elaboration. Can you please share the sample web application using that issue could be reproduced? You can create a new simple web application just to reproduce the issue.

This is a small maven web application that allows you to upload a file, a servlet saves it and uses getDocumentInfo to create a response. You can upload any number of files. When the http session is destroyed (after 2 or 3 minutes), tries to delete the uploaded files.
webapp.png (3.1 KB)

results.png (68.9 KB)

What I am seeing is that not always happens the problem. And after some time, the file that could not be deleted, can be deleted.

I hope this helps…
GDWeb.zip (13.3 KB)

1 Like

@jorgeeflorez,

Thanks for sharing the details.
We are investigating this issue. Your investigation ticket ID is VIEWERJAVA-2153. As there’s any update, you’ll be notified.

@jorgeeflorez,

We are pleased to inform you that VIEWERJAVA-2153 is now fixed in version 20.1.

@atirtahir3, thank you for your help. I will test it in the following days.
Best Regards.
Jorge

1 Like

@jorgeeflorez,

You are welcome.