使用HTTPWebRequest上传到Google云端硬盘非常慢 [英] Uploading to Google Drive using HTTPWebRequest is very slow

查看:783
本文介绍了使用HTTPWebRequest上传到Google云端硬盘非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好:




在我的项目中,我使用的是将数据上传到Google云端硬盘HttpWebRequest的。由于文件大小很大,我使用Resumable upload。我已经将文件分成5 MB的块并上传了块。  对于相同大小的网页浏览器需要几秒钟的时间
,而申请时间超过2分钟。 

In my project I am uploading data to Google drive using HTTPWebrequest. As the file size is large the I am using Resumable uploading. I have divided file in chunks of 5 MB and uploading the chunks.  For the same size of chunk web browser takes few seconds while application is taking more than 2 mins. 

我已经检查过以下设置,但没有或上传速度变化非常小zh。

I have checked with following settings but there is no or very minimal change in uploading speed

                ServicePointManager.UseNagleAlgorithm = false; 

                System.Net.ServicePointManager.CheckCertificateRevocationList = false;

                ServicePointManager.DefaultConnectionLimit      = 1000;

                System.Net.ServicePointManager.Expect100Continue = false;

                ServicePointManager.UseNagleAlgorithm = false; 
                System.Net.ServicePointManager.CheckCertificateRevocationList = false;
                ServicePointManager.DefaultConnectionLimit      = 1000;
                System.Net.ServicePointManager.Expect100Continue = false;

                  httpRequest.Proxy                  =  null;

                 httpRequest.Proxy                  =   null;

              

 这是我的示例代码。如何提高上传速度?提前致谢。

 Here is my sample code. How can I increase the upload speed? Thanks in advance.

 

public bool UploadRequest(byte[] docChunk,long StartOffset,long EndOffset) { HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(URL); httpRequest.Method= "PUT"; httpRequest.ContentLength= docChunk.Length; httpRequest.Headers["Content-Range"] = "bytes " + StartOffset + "-" +EndOffset + "/" + FileSize.ToString(); using (Stream f_ObjHttpStream = httpRequest.GetRequestStream()) { MemoryStream f_ChunkStream = null; f_ChunkStream = new MemoryStream(docChunk); f_ChunkStream.CopyTo(f_ObjHttpStream);//This line execution takes more than 2 mins


f_ObjHttpStream.Flush();

f_ObjHttpStream.Close();

f_ChunkStream.Close();
}

使用(HttpWebResponse httpResponse =(HttpWebResponse)(httpRequest.GetResponse()))
{
if(httpResponse.StatusCode == HttpStatusCode.OK)
{
httpResponse.Close();

返回f_IsUploaded = true;
}
}
}
}

f_ObjHttpStream.Flush(); f_ObjHttpStream.Close(); f_ChunkStream.Close(); } using (HttpWebResponse httpResponse = (HttpWebResponse)(httpRequest.GetResponse())) { if (httpResponse.StatusCode == HttpStatusCode.OK) { httpResponse.Close(); return f_IsUploaded = true; } } } }


推荐答案

Hello Ruyan,

Hello Ruyan,

对于某些上传方式。很明显,Google公司在优化上传操作方面做了大量工作。除了使用浏览器,您还可以选择谷歌同步客户端,您可以将任何您喜欢的内容拖入和移出Drive文件夹。毫无疑问,您可以通过这些工具快速上传文件。

For some upload ways . it is clear that Google company has done much job to optimize the upload action. Beside using browser you also could choose google sync client you can drag whatever you like into and out of the Drive folder.There is no doubt that you upload file fast by these tools.

对于HTTPWebRequest,它只提供WebRequest类的特定于HTTP的实现。我不是谷歌的工作,我想谷歌公司已经为其他上传方式做了一些速度限制工作。

For HTTPWebRequest , it just provides an HTTP-specific implementation of the WebRequest class. I'm not work for google and I guess that google company has done some speed-limit job for other upload ways.

并且有一些关于使用google drive apis上传的信息,你可以参考它。

And there is some information about upload with google drive apis , you could take reference with it.

https://developers.google .com / drive / v3 / web / resumable-upload



祝你好运,


Best regards,

feih_7

注意:此响应包含对第三方万维网站点的引用。 Microsoft提供此信息是为了方便您。 Microsoft不控制这些网站,也未测试在这些网站上找到的任何软件或信息;因此,微软无法对在那里找到的任何软件或信息的质量,安全性或适用性做出任何陈述。使用互联网上的任何软件都存在固有的危险,微软提醒您要确保在从互联网上检索任何软件之前,您需要完全了解风险。 

Note: This response contains a reference to a third-party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet. 


这篇关于使用HTTPWebRequest上传到Google云端硬盘非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆