下面有什么问题?它需要大约2.5小时才能上传2gb文件。通过基于网络的客户端,它花了10分钟做同样的事情。我究竟做错了什么?我怎样才能加快速度呢?感谢。
public static async Task UploadFile(string path)
{
HttpClient httpClient = new HttpClient();
MultipartFormDataContent form = new MultipartFormDataContent();
httpClient.Timeout = Timeout.InfiniteTimeSpan;
FileInfo fileInfo = new FileInfo(path);
FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
StreamContent streamContent = new StreamContent(fileStream);
HttpResponseMessage m = new HttpResponseMessage();
form.Add(streamContent, path.Substring(0, path.Length-4), path);
try
{
m = await httpClient.PostAsync(@"https://xxxxx/api/DataObjects/addAFile?access_token=" + Token, form);
}
catch (Exception ex)
{
throw new Exception("Failed to Post Upload File Request:\n" + @"https://xxxxx/api/DataObjects/addAFile?access_token=" + Token + "\nMessage: " + ex.Message);
}
httpClient.Dispose();
}
这是内存问题吗?将文件编码为流的问题?