Can't wrap my head around to make a MultipartFormDataContent match #152
Replies: 1 comment
-
Later edit: managed to fix this by implementing my own |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everybody,
this is a great package which helps us tremendously in testing our module which uses HttpClient and requests and responses and such.
However for a case when we're uploading a file, I can't seem to understand how I should use it.
Here's how we prepare the upload request in the production code:
var fileContent = new ByteArrayContent(File.ReadAllBytes(pathToFile)); fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); var multipartContent = new MultipartFormDataContent { { fileContent, "file", Path.GetFileName(pathToFile) } }; // add a json in the body, describing the file multipartContent.Add(new StringContent(file1Json), "model"); request.Content = multipartContent;
Nothing complex, it has 2 parts - the actual bytes + a json description of the content - some settings.
In the tests... am not very sure what to use - most likely the
WithExactFormData
orWithFormData
, however it accepts only a dictionary ofstring,string
. Checking the source code I see clearly that if content is MultipartFormDataContent then it allows onlyapplication/x-www-form-urlencoded
.Any hints would be appreciated.
Best regards,
Stefan Gheorghe
Beta Was this translation helpful? Give feedback.
All reactions