首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >怎样才能更快地上传文件?

怎样才能更快地上传文件?
EN

Stack Overflow用户
提问于 2019-04-21 20:32:46
回答 1查看 189关注 0票数 0

我正在尝试用Web客户端加速上传文件的过程,我已经写了一些代码,运行良好,但非常慢,如果我尝试直接从网站上传相同的文件,它将花费更少的时间,有什么建议吗?或者其他我应该使用的库?

代码语言:javascript
复制
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;
}
EN

回答 1

Stack Overflow用户

发布于 2019-04-21 21:06:33

你可以使用HttpWebRequest类从内存上传。这看起来是一种更快的方法。

看看下面的链接。https://web.archive.org/web/20151128202604/http://aspnetupload.com/Upload-File-POST-HttpWebRequest-WebClient-RFC-1867.aspx

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55782757

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档