I try to upload a file to a FlashAir Card using POST. There is a JavaScript-Example available which works on my machine:
cgi="http://flashair/upload.cgi";
$.ajax({ url: cgi,
type: "POST",
data: fd,
processData: false,
contentType: false,
success: function(html){
if ( html.indexOf("SUCCESS") ) {
alert("success");
getFileList(".");
}else{
alert("error");
}
}
});
I try to achieve the same with .NET. This is what I've done:
var cgi="http://flashair/upload.cgi";
byte[] bytes = File.ReadAllBytes(filename);
HttpContent bytesContent = new ByteArrayContent(fileData);
using (var client = new HttpClient())
{
using (var formData = new MultipartFormDataContent())
{
formData.Add(bytesContent, "file");
var response = client.PostAsync(command, formData).Result;
if (!response.IsSuccessStatusCode)
{
return false;
}
return true;
}
}
While the first example works, my C#-Variant also returns a 200 Code (and takes a while which makes me think, that the file is being uploaded), but the file is not saved.
Any idea where is the difference between the two examples which could cause the problem?