Hi I'm attempting to upload a file to an MSMVC controller using the iOS HTTPClient like so :
public async Task UploadPhotoAsync(string fileName, byte[] photoBytes)
{
httpClient = new HttpClient();
try
{
var multipartForm = new MultipartFormDataContent();
var fileContent = new StreamContent(new MemoryStream(photoBytes));
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = "file",
FileName = "test.jpg",
};
fileContent.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
multipartForm.Add(fileContent);
await httpClient.PostAsync("http://192.168.1.80/upload/upload", multipartForm); } catch (Exception ex) { Console.WriteLine(ex.Message); }
}
The problem seems to be with the data received at the controller end... The request arrives at the Controller but the Request.Files.Count is zero even though the Request.TotalBytes count is correct?
Has anyone else experienced any issues with HTTPClient on iOS?
Posts
Hi I'm attempting to upload a file to an MSMVC controller using the iOS HTTPClient like so :
The problem seems to be with the data received at the controller end... The request arrives at the Controller but the Request.Files.Count is zero even though the Request.TotalBytes count is correct?
Has anyone else experienced any issues with HTTPClient on iOS?
I'm running into this same problem. The only way I can get the server to recognize the file is by surrounding the value in quotes:
I test this by sending from WinPhone. On iOS if I try and surround the values with quotes I get a FormatException.
From the mono source:
Any help would be appreciated.
So, this works: