This project is read-only.

Upload File and Response

Dec 29, 2010 at 2:30 PM

Hello, i've want to upload a file to the web server and/or show a response text at the page that said "Upload success" or no. How can i do it. I've a version 2.0 of WebServer

 

In server

           var server = new Server();

           var module = new FileModule();
            module.Resources.Add(new FileResources("/", "C:\\temp\\"));
            server.Add(module);      

 

           HttpListener ss =   HttpListener.Create(IPAddress.Any, 8085);
          
            ss.RequestReceived += new EventHandler<RequestEventArgs>(ss_RequestReceived);
 

            // use one http listener.
            server.Add(ss);

            // start server, can have max 5 pending accepts.
            server.Start(5);

 


        static void ss_RequestReceived(object sender, HttpServer.RequestEventArgs e)
        {

// check if file is upload.html

 

           e.Request.Body.Seek(0, SeekOrigin.Begin);

            byte[] body = new byte[e.Request.Body.Length];

            e.Request.Body.Read(body, 0, (int)e.Request.Body.Length);*/

      ///SAve file function

//

         }

 

 

in index.html something like this

 

<form enctype="multipart/form-data"  method = "post">
     
    <input id="my_file_element" type="file" name="file_1" >
    <input type="submit">

</form>

How can i do show in index.html a successful message string ? and this mode is correct to upload a file with WebServer ?

 

bye and tnx

 

 

 

 

Dec 29, 2010 at 3:08 PM

Check the following property: 

Request.Files["file_1"]

Dec 29, 2010 at 3:14 PM

Tnx for quick reply, but  the e.Request.Files["file_1"] is ever null

 

 

Dec 29, 2010 at 6:52 PM

The http listener do not do anything with the request as you have noticed.

Alternative one:

Switch and use Server class instead. It decodes all bodies.

Alternative two:

Use MultiPartDecoder to decode the body:

var decoder = new MultiPartDecoder();
decoder.Decode(e.Request.Body, e.Request.ContentType, e.Request.Encoding);

Make sure that the stream is at the beginning first.