我正在尝试通过Web客户端加快文件上传的过程,我编写了一些可以正常工作的代码,但是如果我尝试直接从网站上载相同文件,则会非常缓慢,这将减少很多建议时间?或其他我应该使用的库?
static string CreateDownloadLink(string File)
{
string ReturnValue = string.Empty;
try
{
using (WebClient Client = new WebClient())
{
byte[] Response = Client.UploadFile("https://anonfile.com/api/upload", File);
string ResponseBody = Encoding.ASCII.GetString(Response);
if (ResponseBody.Contains("\"error\": {"))
{
ReturnValue += "There was a erorr while uploading the file.\r\n";
ReturnValue += "Error message: " + ResponseBody.Split('"')[7] + "\r\n";
}
else
{
ReturnValue += "Download link: " + ResponseBody.Split('"')[15] + "\r\n";
ReturnValue += "File name: " + ResponseBody.Split('"')[25] + "\r\n";
}
}
}
catch (Exception Exception)
{
ReturnValue += "Exception Message:\r\n" + Exception.Message + "\r\n";
}
return ReturnValue;
}
答案 0 :(得分:1)
您可以使用HttpWebRequest类从内存中上传。这看起来是一种更快的方法。
看看下面的链接。 https://designthinkingworkshop.nl/