I'm trying to write a WCF Restful api to upload file to a server. I've gone through the posts for Multipart Parser, and tried to use them. The problem I'm facing is that when reading the stream content, some special characters in the image file gets replaced and I end up with a file almost twice the original size.
example: Below is one line from the image file
-¦ã09°O ð -ÍQa:BÐ`QËÎâ<Îä\Îæ|ÎèœÎê¼Îì, ;
This gets converted to
�-���09�O � -�Qa:B�`Q���<��\��|������, � ;
My assumption was that this had something to do with the encoding used to read the stream, so I've tried to use StreamReader for this, but with no success.
MultipartParser parser;
using (System.IO.StreamReader reader = new System.IO.StreamReader(stream))
{
var encoding = reader.CurrentEncoding;
parser.Parse(stream, encoding);
}
Edited:
UI piece
<form id="testForm" action="--service url--" method="POST" enctype="multipart/form-data">
<table>
<tr><td>File:</td><td><input type="file" name="Contents"></td></tr>
<tr><td/><td><input type="submit" value="Send"></td></tr>
</table>
</form>
Here's my request from fiddler
Cache-Control: max-age=0
Content-Length: 278783
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryokLIHmhMy8bbelA6
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
------WebKitFormBoundaryokLIHmhMy8bbelA6
Content-Disposition: form-data; name="Contents"; filename="someimage.jpg"
Content-Type: image/jpeg
--file content here---
------WebKitFormBoundaryokLIHmhMy8bbelA6--