WebClient.UploadFileAsync 方法
定义
将指定的本地文件上载到指定的资源。Uploads the specified local file to the specified resource. 这些方法不阻止调用线程。These methods do not block the calling thread.
重载
| UploadFileAsync(Uri, String) |
使用 POST 方法将指定的本地文件上载到指定的资源。Uploads the specified local file to the specified resource, using the POST method. 此方法不会阻止调用线程。This method does not block the calling thread. |
| UploadFileAsync(Uri, String, String) |
使用 POST 方法将指定的本地文件上载到指定的资源。Uploads the specified local file to the specified resource, using the POST method. 此方法不会阻止调用线程。This method does not block the calling thread. |
| UploadFileAsync(Uri, String, String, Object) |
使用 POST 方法将指定的本地文件上载到指定的资源。Uploads the specified local file to the specified resource, using the POST method. 此方法不会阻止调用线程。This method does not block the calling thread. |
UploadFileAsync(Uri, String)
使用 POST 方法将指定的本地文件上载到指定的资源。Uploads the specified local file to the specified resource, using the POST method. 此方法不会阻止调用线程。This method does not block the calling thread.
public:
void UploadFileAsync(Uri ^ address, System::String ^ fileName);
public void UploadFileAsync (Uri address, string fileName);
member this.UploadFileAsync : Uri * string -> unit
Public Sub UploadFileAsync (address As Uri, fileName As String)
参数
- address
- Uri
接收文件的资源的 URI。The URI of the resource to receive the file. 对于 HTTP 资源,此 URI 必须标识可以接受用 POST 方法发送的请求的资源,如脚本或 ASP 页。For HTTP resources, this URI must identify a resource that can accept a request sent with the POST method, such as a script or ASP page.
- fileName
- String
要发送到资源的文件。The file to send to the resource.
例外
address 参数为 null。The address parameter is null.
- 或 --or-
fileName 参数为 null。The fileName parameter is null.
通过组合 BaseAddress 和 address 所构成的 URI 无效。The URI formed by combining BaseAddress and address is invalid.
- 或 --or-
fileName 为 null、为 Empty、包含无效字符或者指定的文件路径不存在。fileName is null, is Empty, contains invalid character, or the specified path to the file does not exist.
- 或 --or-
打开流时发生错误。An error occurred while opening the stream.
- 或 --or-
承载资源的服务器没有响应。There was no response from the server hosting the resource.
- 或 --or-
Content-type 标头以 multipart 开头。The Content-type header begins with multipart.
注解
文件使用自动从线程池分配的线程资源进行异步发送。The file is sent asynchronously using thread resources that are automatically allocated from the thread pool. 若要在文件上传完成时收到通知,请向事件添加事件处理程序 UploadFileCompleted 。To receive notification when the file upload completes, add an event handler to the UploadFileCompleted event.
在发送文件时,此方法不会阻止调用线程。This method does not block the calling thread while the file is being sent. 若要在等待服务器响应的同时发送文件和块,请使用其中一种 UploadFile 方法。To send a file and block while waiting for the server's response, use one of the UploadFile methods.
在 .NET Framework 和 .NET Core 1.0 中,可以通过调用方法取消尚未完成的异步操作 CancelAsync 。In .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.
如果 BaseAddress 属性不是空字符串 ( "" ) , address 则必须是与组合的相对 uri, BaseAddress 才能形成所请求数据的绝对 uri。If the BaseAddress property is not an empty string (""), address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. 如果该 QueryString 属性不是空字符串,则将其追加到 address 。If the QueryString property is not an empty string, it is appended to address.
此方法使用 STOR 命令上传 FTP 资源。This method uses the STOR command to upload an FTP resource. 对于 HTTP 资源,使用 POST 方法。For an HTTP resource, the POST method is used.
备注
当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅 .NET Framework 中的网络跟踪。For more information, see Network Tracing in .NET Framework.
适用于
UploadFileAsync(Uri, String, String)
使用 POST 方法将指定的本地文件上载到指定的资源。Uploads the specified local file to the specified resource, using the POST method. 此方法不会阻止调用线程。This method does not block the calling thread.
public:
void UploadFileAsync(Uri ^ address, System::String ^ method, System::String ^ fileName);
public void UploadFileAsync (Uri address, string? method, string fileName);
public void UploadFileAsync (Uri address, string method, string fileName);
member this.UploadFileAsync : Uri * string * string -> unit
Public Sub UploadFileAsync (address As Uri, method As String, fileName As String)
参数
- address
- Uri
接收文件的资源的 URI。The URI of the resource to receive the file. 对于 HTTP 资源,此 URI 必须标识可以接受用 POST 方法发送的请求的资源,如脚本或 ASP 页。For HTTP resources, this URI must identify a resource that can accept a request sent with the POST method, such as a script or ASP page.
- method
- String
用于将数据发送到资源的方法。The method used to send the data to the resource. 如果为 null,则对于 http 默认值为 POST,对于 ftp 默认值为 STOR。If null, the default is POST for http and STOR for ftp.
- fileName
- String
要发送到资源的文件。The file to send to the resource.
例外
address 参数为 null。The address parameter is null.
- 或 --or-
fileName 参数为 null。The fileName parameter is null.
通过组合 BaseAddress 和 address 所构成的 URI 无效。The URI formed by combining BaseAddress and address is invalid.
- 或 --or-
fileName 为 null、为 Empty、包含无效字符或者指定的文件路径不存在。fileName is null, is Empty, contains invalid character, or the specified path to the file does not exist.
- 或 --or-
打开流时发生错误。An error occurred while opening the stream.
- 或 --or-
承载资源的服务器没有响应。There was no response from the server hosting the resource.
- 或 --or-
Content-type 标头以 multipart 开头。The Content-type header begins with multipart.
注解
文件使用自动从线程池分配的线程资源进行异步发送。The file is sent asynchronously using thread resources that are automatically allocated from the thread pool. 若要在文件上传完成时收到通知,请向事件添加事件处理程序 UploadFileCompleted 。To receive notification when the file upload completes, add an event handler to the UploadFileCompleted event.
在发送文件时,此方法不会阻止调用线程。This method does not block the calling thread while the file is being sent. 若要在等待服务器响应的同时发送文件和块,请使用其中一种 UploadFile 方法。To send a file and block while waiting for the server's response, use one of the UploadFile methods.
在 .NET Framework 和 .NET Core 1.0 中,可以通过调用方法取消尚未完成的异步操作 CancelAsync 。In .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.
如果 BaseAddress 属性不是空字符串 ( "" ) , address 则必须是与组合的相对 uri, BaseAddress 才能形成所请求数据的绝对 uri。If the BaseAddress property is not an empty string (""), address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. 如果该 QueryString 属性不是空字符串,则将其追加到 address 。If the QueryString property is not an empty string, it is appended to address.
此方法使用 STOR 命令上传 FTP 资源。This method uses the STOR command to upload an FTP resource. 对于 HTTP 资源,使用 POST 方法。For an HTTP resource, the POST method is used.
备注
当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅 .NET Framework 中的网络跟踪。For more information, see Network Tracing in .NET Framework.
适用于
UploadFileAsync(Uri, String, String, Object)
使用 POST 方法将指定的本地文件上载到指定的资源。Uploads the specified local file to the specified resource, using the POST method. 此方法不会阻止调用线程。This method does not block the calling thread.
public:
void UploadFileAsync(Uri ^ address, System::String ^ method, System::String ^ fileName, System::Object ^ userToken);
public void UploadFileAsync (Uri address, string? method, string fileName, object? userToken);
public void UploadFileAsync (Uri address, string method, string fileName, object userToken);
member this.UploadFileAsync : Uri * string * string * obj -> unit
Public Sub UploadFileAsync (address As Uri, method As String, fileName As String, userToken As Object)
参数
- address
- Uri
接收文件的资源的 URI。The URI of the resource to receive the file. 对于 HTTP 资源,此 URI 必须标识可以接受用 POST 方法发送的请求的资源,如脚本或 ASP 页。For HTTP resources, this URI must identify a resource that can accept a request sent with the POST method, such as a script or ASP page.
- method
- String
用于将数据发送到资源的方法。The method used to send the data to the resource. 如果为 null,则对于 http 默认值为 POST,对于 ftp 默认值为 STOR。If null, the default is POST for http and STOR for ftp.
- fileName
- String
要发送到资源的文件。The file to send to the resource.
- userToken
- Object
一个用户定义对象,此对象将传递给完成异步操作后所调用的方法。A user-defined object that is passed to the method invoked when the asynchronous operation completes.
例外
address 参数为 null。The address parameter is null.
- 或 --or-
fileName 参数为 null。The fileName parameter is null.
通过组合 BaseAddress 和 address 所构成的 URI 无效。The URI formed by combining BaseAddress and address is invalid.
- 或 --or-
fileName 为 null、为 Empty、包含无效字符或者指定的文件路径不存在。fileName is null, is Empty, contains invalid character, or the specified path to the file does not exist.
- 或 --or-
打开流时发生错误。An error occurred while opening the stream.
- 或 --or-
承载资源的服务器没有响应。There was no response from the server hosting the resource.
- 或 --or-
Content-type 标头以 multipart 开头。The Content-type header begins with multipart.
注解
文件使用自动从线程池分配的线程资源进行异步发送。The file is sent asynchronously using thread resources that are automatically allocated from the thread pool. 若要在文件上传完成时收到通知,请向事件添加事件处理程序 UploadFileCompleted 。To receive notification when the file upload completes, add an event handler to the UploadFileCompleted event.
在发送文件时,此方法不会阻止调用线程。This method does not block the calling thread while the file is being sent. 若要在等待服务器响应的同时发送文件和块,请使用其中一种 UploadFile 方法。To send a file and block while waiting for the server's response, use one of the UploadFile methods.
在 .NET Framework 和 .NET Core 1.0 中,可以通过调用方法取消尚未完成的异步操作 CancelAsync 。In .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.
如果 BaseAddress 属性不是空字符串 ( "" ) , address 则必须是与组合的相对 uri, BaseAddress 才能形成所请求数据的绝对 uri。If the BaseAddress property is not an empty string (""), address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. 如果该 QueryString 属性不是空字符串,则将其追加到 address 。If the QueryString property is not an empty string, it is appended to address.
此方法使用 STOR 命令上传 FTP 资源。This method uses the STOR command to upload an FTP resource. 对于 HTTP 资源,使用 POST 方法。For an HTTP resource, the POST method is used.
备注
当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅 .NET Framework 中的网络跟踪。For more information, see Network Tracing in .NET Framework.