将文件上载到服务器时出现的所有异常

本文关键字:异常 文件 上载 服务器 | 更新日期: 2023-09-27 18:21:25

我使用以下函数将Unity项目的数据发送到服务器:

public void UploadFile(string filepath)
{
 // Get an instance of WebClient
 WebClient client = new System.Net.WebClient();
 // parse the ftp host and file into a uri path for the upload
 Uri uri = new Uri(m_FtpHost + new FileInfo(filepath).Name);
 // set the username and password for the FTP server
 client.Credentials = new System.Net.NetworkCredential(m_FtpUsername, m_FtpPassword);
 // upload the file asynchronously, non-blocking.
 client.UploadFileAsync(uri, "STOR", filepath);
}

我想要的是找到所有可能的异常,当我将文件上传到服务器时,我可以捕捉到这些异常。有关于这方面的清单或教程吗?编辑:我想处理的两个重要问题是互联网连接和存储问题(空间不足)。

将文件上载到服务器时出现的所有异常

您使用的方法WebClient.UploadFileAsync中没有记录它吗?

例外情况

  • ArgumentNullException:地址参数为null-或-fileName参数为null
  • WebExceptionBaseAddress与地址组合形成的URI无效-或-fileName为null、为Empty、包含无效字符或指定的文件路径不存在。-或-打开流时出错。-或-承载资源的服务器没有响应。-或-Content类型标头以multipart开头

WebException.Status被设置为指示错误。