locked
problems firing httphandler when uploading a file RRS feed

  • Question

  • User607408424 posted
    Hi all I hope someone can help with this cos its really starting to p!*s me off. What I need to do is upload a files, im using an httphandler to achieve this component written by Rasmus Hartvig <post>http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=55127</post> The handler works fine but I have to do a postback to add some information before uploading the file, so when the postback has completed I have lost the file in the request. I have tried to manually invoke the handler dim uh as new uploadHandler uh.processRequest(httpcontext.current) which almost works it knows that a file is in the request but can't get it out. I ve tried firing a javascript function which alters the action of the form (after the postback) to fire to handler and that works but I loose the file in the request. If anyone can help it would be much appreciated, part of me tells me Im just being a fool and the answer is staring me in the face but if it is I can't see it. thanks in advance Dan
    Tuesday, April 6, 2004 6:52 AM

All replies

  • User-732283392 posted
    Correct me if i'm wrong: you've put the httphandler in the bin, registered in the configuration file. the scenario is: a user goes to a page that has an upload html control and the user selects the file, hits "submit" or whatever, and the server gets the request... but then you say you need to do a postback to add some information *before* uploading the file? if you do it before you upload the file, then how could you lose the file in the request because it's done *before* the actual upload? i'm a little confused as to what you're trying to do exactly. Why not add the information you want to add to the same request that the file is sent in and parse out those variables when you get the raw request stream?
    Tuesday, April 6, 2004 12:02 PM
  • User607408424 posted
    Hi I didn't think I explained it very well. what I need to do is have the user pick a file, click submit, add that information to the database and then upload the file via the httphandler. But because I'm doing a postback the action of the form is set to itself, but for the handler to kick in I need the action of the form to be the file that is declared in the web.config file. So what I tried to do was postback to the form do my db stuff, I then add an onLoad attribute to the body tag which calls a javascript function and that function then changes the form action to the page for the httphandler and resubmits the form. This works fine up to this point but when I debug the httphandler the file that was in the request is no longer there. Is that any better? cheers Dan
    Tuesday, April 6, 2004 3:44 PM
  • User-732283392 posted
    Ah, yes, much better. In the form declaration do this: <form runat="server" action="pagetorecieveupload.aspx"> the action attribute specifes the page to recieve the request. This way you won't need to do two postbacks and can combine the processing of updating the DB and saving the file in one request.
    Tuesday, April 6, 2004 5:29 PM
  • User-732283392 posted
    d'oh! nevermind that. i forgot ASP.NET will overwrite any value in the action attribute to be the same form as the page. I actually created a large file uploading component (and got a lot of information from that great thread that you mentioned). I used an HttpHandler implementation instead of the HttpModule as well. What i did was just used good old HTML and didn't use any ASP.NET runat="server" on the controls (you can still access the values of the form, just not in an object oriented fashion, i.e. Request.Params["uploadFile"] etc.) And i set the action property to the page that would pick up the request for uploading files. Since the uploader works with the raw request stream, this isn't really a factor anyway. Also, what happens when you set the web.config file to the same as the upload page? In the HttpHandler, you could check to see if it's a postback, if not, just return the processing to the page handler and if it is a postback, start up your uploading action. that's another alternative if you don't like using just plain HTML.
    Tuesday, April 6, 2004 5:38 PM
  • User607408424 posted
    Hi I tried that but .net altered the action to be that of the itself at runtime, and completley removed my decalared action. Is there any way to manually invoke an httphandler eg. dim uh as new uploadhandler etc. Dan
    Tuesday, April 6, 2004 6:33 PM
  • User-732283392 posted
    It won't alter the action if you use plain html (i.e. remove the runat="server" attribute to the form element, and all subsequent form input elements). That way you can control which page handles the submission. That's the way i do it. To my knowledge, you can't invoke an httphandler, at least not in the way you want because the user has to submit the file--you can't invoke a file submission from the user.
    Wednesday, April 7, 2004 10:27 AM
  • User607408424 posted
    I did manage to fire the httphandler, during the postback, if I create the handler, and then pass in the current context it does work to an extent, the handler fires and during debugging when I check the content length in the processRequest function the file is there but when it tries to pull the information out of the request into the buffer it seems to get stuck in a loop. I know its a pain the to have to do the postback first its just the way I have to do things. cheers Dan
    Wednesday, April 7, 2004 10:56 AM
  • User-732283392 posted
    Dan, Like i said, I implemented my own file uploading httphandler for large files, just as you have done. If you use plain HTML instead of ASP.NET controls, you can specify, in the action attribute of the form element, the page you wish to have handle the request. if you do this, you will have everything that you need. You won't lose anything because you won't be able to access form values using controlname.value because you're handling the raw request yourself anyway. If you feel that you have to do two postbacks, then i would probably store something in the request or session collection to identify which values that are first posted go with the second post when the file submission comes in.
    Wednesday, April 7, 2004 11:09 AM