I have an ASP.NET web application that uses jQuery on client side. On one of the web forms I have a bunch of controls to fill, and an upload control. User can run upload while filling other entries on the form. When user saves the form, all data including file is stored into database . The question is what to do with uploaded file while user fills the form? I have two possible solutions, but don't know which of them is more optimal
- Cache uploaded file, and later, while saving, retrieve it and store into database with all other data.
- Save file in temporary folder, and then read it.
What is the best solution for this? Thanks in advance.
Like other people mentioned - you can simply upload it. You can do it in many ways:
How about:
3: Store it in the database but marked as in an incomplete state
This could be a separate table, or the same table with a status column.
I think the most appropriate solution will be storing uploaded file in cache. Here is the code
The fileKey GUID can be stored in ViewState, or sent as the response to client. Later, when whole form will be saved, cached file can be retrieved and stored into database with other data. The good thing about this method is that if user navigates from the page cached file will expire, thus avoiding resource flooding. We can set expiration time using
function.
I fail to see the difference between the 2 options: what do you mean by caching the file? Isn't it the same as saving to a temp folder?
AFAIK, most sites will not start uploading until the entire form is filled up (what if your user cancels, or browses away?). They then display an interim progress bar ("please wait while we're analyzing your data...").
As a general design rule, receiving partial data at any point in time may lead to inconstant data later. If you must do it in steps, change your form to a wizard.