Fork me on GitHub

7 Sept 2009

Session Bound Temporary Files

I've just released Session Temp Files, a very simple plugin for managing a temporary file storage space bound to the HTTP session. I'm working on something where a user uploads a file at the start of a webflow conversation, the flow then validates the file and may require the user to enter extra information before finally the file is saved and an associated record is added to the database. The uploaded files needed to be stored somewhere between the initial upload phase and the successful outcome of the flow where they will be copied in to a permanent storage space. The file is really too big to keep in memory in the flow scope. It's easy enough to create a temp file and delete it at the end of the flow (even if the user cancels out of the flow) however users can also do things like close the browser, suddenly decide to do something different and type in a new URL, etc. The webflow then gets abandoned in an intermediate state. The flow itself will be destroyed when the HTTP session ends but the temp files I created will hang around until the OS decides to sweep the temp directory.

The plugin simply allows you to create a directory within the normal temp directory -"" - that will get deleted when the HTTP session expires. It binds two new methods on to HTTPSession: getTempDir() returns the session's temp directory, creating it if it doesn't exist and createTempFile(prefix,suffix) works like File.createTempFile except that the file is created inside the directory returned by getTempDir.

The code is up on GitHub and the plugin is available from the standard Grails plugin repository via grails install-plugin session-temp-files.


Williamchen said...

I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenter’s here! It’s forever nice when you can not only be knowledgeable, but also entertained!That is the outstanding mindset, however is just not help to make every since whatsoever preaching about that matter. Almost any technique many thanks in addition to I had try to promote your own article in to delicious nevertheless it is it seems that a dilemma using your in order sites can you please recheck the idea.
Visit : Best essay writing service

lilyjohnson said...

Hi guys! There are many essay writing service providers available but writing a quality essay at an affordable rate is really hard to find. I think this help to prepare a quality essay at an affordable rate. Thanks for the information shared.

Andrew Lewis said...

Hey! I agree that there should really be a way to retain the temp files that get deleted for some reason. If you have introduced an idea which you think is effective so I hope it gets approved as soon as possible. As a student, I keep on switching web pages on and off. Sometimes while searching for a research paper and sometimes while looking for someone to make my assignment for me.

1292lillyS said...

Thanks for sharing this with everyone. You have no idea how long I've been looking for something like this Session Temp Files. It's so incredible that I find you so unexpected. I was looking for letter writing service online for my study because I have no idea how to write my work.