Reputation: 86085
As title, how to specify additional form parameters when uploading file using webclient?
Upvotes: 8
Views: 6703
Reputation: 1038850
You can't do this with a WebClient
. You will need to manually generate the multipart/form-data
request. Here's an example which could be easily adapted. You will just need to insert the file contents at the parameter you like. In this example I used a StreamWriter
but if your file is binary you would probably want to directly write to the request stream.
The idea is to achieve RFC 1867.
If you don't want to go this route and those values are not very big you could probably pass the additional parameters at the request string and continue using UploadFile
method. Of course the target url must be capable of reading those values from the query string.
Upvotes: 8