I'm using RestSharp's AddFile and it's working close to fine except my files end up getting broken due to this header information that's being added.
-------------------------------28947758029299
Content-Disposition: form-data; name="user.png"; filename="user.png"
Content-Type: image/png
This was just a test image I uploaded. If I remove these lines from the file then it opens fine, otherwise it seems to be corrupt. Is it possible for me to use AddFile without this stuff getting added?
Current code:
string contentType = MimeMapping.GetMimeMapping("~/uploads/" + filename); //image/png etc
request.AddFile(filename, Server.MapPath("~") + "\\uploads\\" + filename, contentType);
IRestResponse response = client.Execute(request);
Also tried this with the same result:
request.AddHeader("Content-Type", contentType);
byte[] bytes = File.ReadAllBytes(Server.MapPath("~") + "\\uploads\\" + filename);
request.AddBody(new {myFile = File.ReadAllBytes(Server.MapPath("~") + "\\uploads\\" + filename) });
Also this (no files went through at all here): Edit: this worked actually
string contentType = MimeMapping.GetMimeMapping("~/uploads/" + filename);
byte[] bytes = File.ReadAllBytes(Server.MapPath("~") + "\\uploads\\" + filename);
request.AddHeader("Content-Type", contentType);
request.AddParameter(contentType, bytes, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);