Method ExtInternet.AddFile
Overload
Adds a file field. Uses System.Net.Http.MultipartFormDataContent.Add. Please read remarks about disposing.
public static MultipartFormDataContent AddFile(this MultipartFormDataContent t, string name, string file, string contentType = null, string fileName = null)
Parameters
t (MultipartFormDataContent) |
name (string)
Field name. |
file (string)
File path. |
contentType (string)
|
fileName (string)
Filename. If |
Returns
MultipartFormDataContent
This. |
Exceptions
ArgumentException |
Exception
Exceptions of filesystem.loadStream. |
Remarks
Opens the file and stores the stream in this MultipartFormDataContent object. Won't auto-close it after uploading. To close files, dispose this MultipartFormDataContent object, for example with using
like in the example. Else the file will remain opened/locked until this process exits or until next garbage collection.
Examples
using var content = internet.formContent(("name1", "value1"), ("name2", "value2")).AddFile("name3", @"C:\Test\file.png");
string s = internet.http.Post("https://httpbin.org/anything", content).Text();