Httplistener and file upload

后端 未结 4 752
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 20:04

I am trying to retrieve an uploaded file from my webserver. As the client sends its files through a webform (random files), I need to parse the request to get the file out a

4条回答
  •  [愿得一人]
    2020-12-05 20:45

    The problem is you are reading the file as text.

    You need to read the file as a bytearray instead and using the BinaryReader is better and easier to use than StreamReader:

    Byte[] bytes;
    using (System.IO.BinaryReader r = new System.IO.BinaryReader(request.InputStream))
    {
        // Read the data from the stream into the byte array
        bytes = r.ReadBytes(Convert.ToInt32(request.InputStream.Length));
    }
    MemoryStream mstream = new MemoryStream(bytes);
    

提交回复
热议问题