I am trying to create integration test for my upload picture action. Raw request created from browser is like below;
POST /api/UpdateImage HTTP/1.1
Host: upload.qwe.com
Authorization: bearer KuThe6Wx/CW1TO/HVS+u3Tov3MRh8qTMDrSvQ09nMnP4OgYp
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=Boundary-D60385FA-C164-45B0-A81E-0F6488F8E1E1
Content-Length: 375488
Accept-Language: en-us
Accept: */*
Connection: keep-alive
User-Agent: Chrome
Pragma: no-cache
Cache-Control: no-cache
--Boundary-D60385FA-C164-45B0-A81E-0F6488F8E1E1
Content-Disposition: form-data; name="fileName"
image.jpg
--Boundary-D60385FA-C164-45B0-A81E-0F6488F8E1E1
Content-Disposition: form-data; name="fileUpload"; filename="image.jpg"
Content-Type: image/jpeg
And my code for integration test;
MultipartContent multipartContent = new MultipartContent();
multipartContent.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=Boundary-D60385FA-C164-45B0-A81E-0F6488F8E1E1");
ContentDispositionHeaderValue contentDispositionHeaderValue = new ContentDispositionHeaderValue("form-data")
{
Name = "fileName"
};
multipartContent.Headers.ContentDisposition = contentDispositionHeaderValue;
// StreamContent
FileStream fileStream = File.Open(@"./Assets/" + fileName, FileMode.Open);
StreamContent stream = new StreamContent(fileStream);
multipartContent.Add(stream);
httpRequestMessage.Content = multipartContent;
return httpRequestMessage;
But I cannot set second part of the data which has Content-Disposition: form-data; name="fileUpload"; filename="image.jpg"
How can I achieve this?
Problem Summary: