Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify form parameter when using webclient to upload file

As title, how to specify additional form parameters when uploading file using webclient?

like image 235
user496949 Avatar asked Nov 21 '10 09:11

user496949


1 Answers

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.

like image 183
Darin Dimitrov Avatar answered Nov 02 '22 05:11

Darin Dimitrov