Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi
I have a page having a TextArea(HTML) and Post Button(HTML) just bellow that Textarea.
On the click of that button I am calling $.ajax() method by which I am calling an appropiate controller action method.There is a <input type="file"> uploader just above the Post Button from where user can upload any file & that file is uploaded to the server by using FormData() class object.The whole flow ofthe code is as follows

1. User enters the text in textarea
2. Upload an attachment file(if required)
3. Then Click on the Post Button
4. A Javascript function is called who then uses FormData() to upload a file with particular key name
5. $.ajax() method is called and it calls controller's action method where I store the file in Session
6. Then again I call $.ajax() which calls controller's another action method which is responsible for adding the text to the database and in this method I retrive file from Session which I store in step 5.

Now the problem is that sometimes action method of step 5 is not called due to which I don't get any attachment file in step 6 action method. Though out of 10 times it is happening 1 time that I post a text with an attachment and that text comes without attachment.Previously I thought there is some caching issue so I decorate the controller's action method with [OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)] the scenerio happens in this way Suppose I have posted following 7 text


1. Com1 (With Attachment File “List of UI & Database Objects”)(Uploaded Successfully)
2. Com2(Without Attachment) (Uploaded Successfully)
3. Com3(With Attachment File “List of UI & Database Objects”) ”)(Uploaded Successfully)
4. Com4(Without Attachment) ”)(Uploaded Successfully)
5. Com5(With Attachment File “List of UI & Database Objects”)(Uploaded But Attachment Is Absent)
6. Com6(With Attachment File “List of UI & Database Objects”)(Uploaded Successfully)
7. Com7(With Attachment File “List of UI & Database Objects”)(Uploaded Successfully)

Here Com5 is not uploaded with attachment rest all the comments are uploaded

With Warm Regards
Piyush Maitrey
Posted

1 solution

Maybe it is better if you save the uploaded file temporarily in a tmp folder given a specific name to recognize it. Then in the second call for the text, you can seek the temporary file and save it in the permanent folder. Storing large objects in session is not a very good practice.
After success just delete the tmp file to save some space.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900