Add better support for adding form file parameters to web requests #6412
+14
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Something I ended up needing in the course of BSS work.
The previous implementation would treat files as a straight dictionary, as in you could have only one file with a given parameter name in a request. This isn't how
multipart/form-data
really works; you're allowed to send multiple files in scope of a single parameter.Additionally, the request did not permit specifying a filename, which is yet another thing I need for BSS purposes.
I don't believe this method has any real consumers, yet anyhow:
Breaking changes
WebRequest.AddFile()
has been altered to provide an API closer to what the HTTP specs intended, and to allow sending multiple files for a given request parameter. To that end:The signature of the method has changed from
to
Calling
.AddFile()
with the same first parameter (formerly calledname
, now calledparamName
) twice will result in two files being sent in the request, rather than the second call overwriting the file added by the first one.If the
filename
parameter is not explicitly specified in the method call, the filename given in theContent-Disposition
header of the multipart request has changed from being equal to the parameter name toblob
. This is consistent with JavaScriptFormData
API behaviour.