How to delete files uploaded after applet consumes data?
OK. So I'm implementing my own Http server purely in Java. I cannot ask the user to upload files to an applet, but I can upload files from URL's. So I can upload the file into a URL (that my Http server can then serve up the file with the correct mime-type and all that good stuff), then pass that URL to the applet as a parameter:
<applet code="my_applet.myApplet" archive="/myApplet.jar" width="100%" height="100%">
<param name="url" value="URL"/>
</applet>
Then I can read in this value in the applet:
public void int(){
...
String fileURL = this.getParameter("url");
...
}
from here I can read the file the user uploaded...
HERE IS MY QUESTION:
how can gracefully delete this file after the applet reads the data (into the users memory). I suspect the only way is to generate a GET request on behalf of the user (from the applet), that requests the deletion of their uploaded file. The problem with this is that if I'm doing completely unsecure stuff, then this allows a user to request a delete of any file (well at least any file the server recognizes)...but I suppose I could easily limit the scope of what could be deleted by anybody (at any time).
The other idea I have would be to simply periodically delete all of those temp files (within the server)...so any suggestions?
Comments
I'm having a little trouble understanding what you mean, but from what I get you want the user to enter a url...then your server gets the data from that url, and after it uses it you want to delete that file that was downloaded?
When you get the file you can use the File class to get the string name of the file as follows:
File file = new File("Path to file" + "file name"); // I assume you can get the file name when you download it to your server? And its going to a specific path so just tag on the file name to the path?
if(file.exists())
file.delete();