filipeavsilva / http-multipart-parser

A simple HTTP multipart parser for .NET (3.5)
MIT License
7 stars 4 forks source link

Boundary is appended to stream data. #2

Closed sharov-am closed 10 years ago

sharov-am commented 10 years ago

Hello, Filipe! Thank you very much for very useful library!

When I'm trying write stream to file boundary is appended to the end of file. Something like: (normal data)

------WebKitFormBoundary9dyqSN7lCX6zkMWS with zero bytes appended.

Here is http header:

Host: localhost:7000 Connection: keep-alive Content-Length: 44318 Origin: http://localhost:7000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Content-Type: multipart/form-data; boundary=----WebKitFormBoundary9dyqSN7lCX6zkMWS Accept: / Referer: http://localhost:7000/service/15 Accept-Encoding: gzip,deflate,sdch Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4

------WebKitFormBoundary9dyqSN7lCX6zkMWS Content-Disposition: form-data; name="file"; filename="file20.SNX" Content-Type: application/octet-stream

(data starts here...)

I'm using WCF REST service and following code:

parser = new HTTPMultipartParser(myStream, FileHandlingType.ALL_STREAMED); foreach (StreamedFileData mdata in parser.Parse()) { if (mdata.IsFile && mdata.IsBinary) mdata.ToFile(Path.Combine(Environment.CurrentDirectory, mdata.FileName)); }

WCF operation described like this:

[OperationContract] [WebInvoke(UriTemplate = "/add", Method = "POST")] string AddEntityWithStream(Stream myStream);

I send additional text (jsoned) data, and they are parsed and recognized well.

What can be the cause?

filipeavsilva commented 10 years ago

Hi! I'm glad this library could be useful to you. I'll admit that the streaming features still need a bit of work. I haven't had much time to work on this, but I'll look at this issue. I'll let you know when I have something :)

Thank you for reaching out!

filipeavsilva commented 10 years ago

sharov-am, from the tests I made I think this issue is fixed. Please let me know if you have any more trouble. (Also, yes, I should create a test suite for this...)