views:

20

answers:

0

I downloaded the source project from the website, using as is, except I changed the target file from upload.php to upload.aspx, which contains the following code to receive the file data:

        int chunk = Request.QueryString["chunk"] != null ? int.Parse(Request.QueryString["chunk"]) : 0;
        string fileName = Path.GetFileName(Request.Files[0].FileName);

        // Read stream
        BinaryReader br = new BinaryReader(Request.InputStream);
        byte[] buffer = br.ReadBytes((int)br.BaseStream.Length);
        br.Close();
        //byte[] appended = buffer.Take(149).ToArray();

        // Write stream
        BinaryWriter bw = new BinaryWriter(File.Open(Server.MapPath("~/uploadfiles" + fileName), chunk == 0 ? FileMode.Create : FileMode.Append));
        bw.Write(buffer);
        bw.Close();

The problem is when I upload a jpg file, or any other file, there is data prepended and appended to every chunk, that obviously makes the file corrupted, and increases the file size. Any idea why that would happen?