pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <tfoot id='yKcv0'></tfoot>
    1. <small id='yKcv0'></small><noframes id='yKcv0'>

        <bdo id='yKcv0'></bdo><ul id='yKcv0'></ul>

      <legend id='yKcv0'><style id='yKcv0'><dir id='yKcv0'><q id='yKcv0'></q></dir></style></legend>
        <i id='yKcv0'><tr id='yKcv0'><dt id='yKcv0'><q id='yKcv0'><span id='yKcv0'><b id='yKcv0'><form id='yKcv0'><ins id='yKcv0'></ins><ul id='yKcv0'></ul><sub id='yKcv0'></sub></form><legend id='yKcv0'></legend><bdo id='yKcv0'><pre id='yKcv0'><center id='yKcv0'></center></pre></bdo></b><th id='yKcv0'></th></span></q></dt></tr></i><div class="c2kmes2" id='yKcv0'><tfoot id='yKcv0'></tfoot><dl id='yKcv0'><fieldset id='yKcv0'></fieldset></dl></div>
      1. C# - 以字節塊從 Google Drive 下載

        C# - Downloading from Google Drive in byte chunks(C# - 以字節塊從 Google Drive 下載)

              <tbody id='91zae'></tbody>
          1. <tfoot id='91zae'></tfoot>

            <i id='91zae'><tr id='91zae'><dt id='91zae'><q id='91zae'><span id='91zae'><b id='91zae'><form id='91zae'><ins id='91zae'></ins><ul id='91zae'></ul><sub id='91zae'></sub></form><legend id='91zae'></legend><bdo id='91zae'><pre id='91zae'><center id='91zae'></center></pre></bdo></b><th id='91zae'></th></span></q></dt></tr></i><div class="c22eoeq" id='91zae'><tfoot id='91zae'></tfoot><dl id='91zae'><fieldset id='91zae'></fieldset></dl></div>

                <bdo id='91zae'></bdo><ul id='91zae'></ul>
              • <small id='91zae'></small><noframes id='91zae'>

                • <legend id='91zae'><style id='91zae'><dir id='91zae'><q id='91zae'></q></dir></style></legend>
                  本文介紹了C# - 以字節塊從 Google Drive 下載的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我目前正在為網絡連接較差的環境進行開發.我的應用程序有助于自動為用戶下載所需的 Google Drive 文件.它對于小文件(從 40KB 到 2MB)工作得相當好,但對于大文件(9MB)卻經常失敗.我知道這些文件大小可能看起來很小,但就我客戶的網絡環境而言,Google Drive API 經常出現 9MB 文件失敗.

                  I'm currently developing for an environment that has poor network connectivity. My application helps to automatically download required Google Drive files for users. It works reasonably well for small files (ranging from 40KB to 2MB), but fails far too often for larger files (9MB). I know these file sizes might seem small, but in terms of my client's network environment, Google Drive API constantly fails with the 9MB file.

                  我已經得出結論,我需要以較小的字節塊下載文件,但我不知道如何使用 Google Drive API 做到這一點.我一遍又一遍地閱讀了 this,并嘗試了以下代碼:

                  I've concluded that I need to download files in smaller byte chunks, but I don't see how I can do that with Google Drive API. I've read this over and over again, and I've tried the following code:

                  // with the Drive File ID, and the appropriate export MIME type, I create the export request
                  var request = DriveService.Files.Export(fileId, exportMimeType);
                  
                  // take the message so I can modify it by hand
                  var message = request.CreateRequest();
                  var client = request.Service.HttpClient;
                  
                  // I change the Range headers of both the client, and message
                  client.DefaultRequestHeaders.Range =
                      message.Headers.Range =
                      new System.Net.Http.Headers.RangeHeaderValue(100, 200);
                  var response = await request.Service.HttpClient.SendAsync(message);
                  
                  // if status code = 200, copy to local file
                  if (response.IsSuccessStatusCode)
                  {
                      using (var fileStream = new FileStream(downloadFileName, FileMode.CreateNew, FileAccess.ReadWrite))
                      {
                          await response.Content.CopyToAsync(fileStream);
                      }
                  }
                  

                  但是,生成的本地文件(來自 fileStream)仍然是全長的(即 ??40KB 驅動器文件為 40KB 文件,9MB 文件為 500 內部服務器錯誤).在旁注中,我還嘗試了 ExportRequest.MediaDownloader.ChunkSize,但據我觀察,它只會改變 ExportRequest.MediaDownloader.ProgressChanged 回調的頻率調用(即如果 ChunkSize 設置為 256 * 1024,回調將每 256KB 觸發一次).

                  The resultant local file (from fileStream) however, is still full-length (i.e. 40KB file for the 40KB Drive file, and a 500 Internal Server Error for the 9MB file). On a sidenote, I've also experimented with ExportRequest.MediaDownloader.ChunkSize, but from what I observe it only changes the frequency at which the ExportRequest.MediaDownloader.ProgressChanged callback is called (i.e. callback will trigger every 256KB if ChunkSize is set to 256 * 1024).

                  我該如何繼續?

                  推薦答案

                  您似乎正朝著正確的方向前進.從您上次的評論來看,請求將根據塊大小更新進度,因此您的觀察是準確的.

                  You seemed to be heading in the right direction. From your last comment, the request will update progress based on the chunk size, so your observation was accurate.

                  查看 SDK 中 MediaDownloader 的源代碼找到了以下(強調我的)

                  核心下載邏輯.我們下載媒體并將其寫入一次輸出流 ChunkSize 個字節,提高 ProgressChanged每個塊之后的事件.分塊行為在很大程度上是歷史性的工件:先前的實現發出多個 Web 請求,每個請求對于 ChunkSize 字節.現在我們在一個請求中完成所有事情,但是 API為了兼容性,保留了客戶端可見的行為.

                  The core download logic. We download the media and write it to an output stream ChunkSize bytes at a time, raising the ProgressChanged event after each chunk. The chunking behavior is largely a historical artifact: a previous implementation issued multiple web requests, each for ChunkSize bytes. Now we do everything in one request, but the API and client-visible behavior are retained for compatibility.

                  您的示例代碼只會下載一個從 100 到 200 的塊.使用這種方法,您必須跟蹤索引并手動下載每個塊,將它們復制到每個部分下載的文件流中

                  Your example code will only download one chunk from 100 to 200. Using that approach you would have to keep track of an index and download each chunk manually, copying them to the file stream for each partial download

                  const int KB = 0x400;
                  int ChunkSize = 256 * KB; // 256KB;
                  public async Task ExportFileAsync(string downloadFileName, string fileId, string exportMimeType) {
                  
                      var exportRequest = driveService.Files.Export(fileId, exportMimeType);
                      var client = exportRequest.Service.HttpClient;
                  
                      //you would need to know the file size
                      var size = await GetFileSize(fileId);
                  
                      using (var file = new FileStream(downloadFileName, FileMode.CreateNew, FileAccess.ReadWrite)) {
                  
                          file.SetLength(size);
                  
                          var chunks = (size / ChunkSize) + 1;
                          for (long index = 0; index < chunks; index++) {
                  
                              var request = exportRequest.CreateRequest();
                  
                              var from = index * ChunkSize;
                              var to = from + ChunkSize - 1;
                  
                              request.Headers.Range = new RangeHeaderValue(from, to);
                  
                              var response = await client.SendAsync(request);
                  
                              if (response.StatusCode == HttpStatusCode.PartialContent || response.IsSuccessStatusCode) {
                                  using (var stream = await response.Content.ReadAsStreamAsync()) {
                                      file.Seek(from, SeekOrigin.Begin);
                                      await stream.CopyToAsync(file);
                                  }
                              }
                          }
                      }
                  }
                  
                  private async Task<long> GetFileSize(string fileId) {
                      var file = await driveService.Files.Get(fileId).ExecuteAsync();
                      var size = file.size;
                      return size;
                  }
                  

                  這段代碼對驅動 api/server 做了一些假設.

                  This code makes some assumptions about the drive api/server.

                  • 服務器將允許分塊下載文件所需的多個請求.不知道請求是否受到限制.
                  • 服務器仍然接受 Range 標頭,如開發人員文檔中所述
                  • That the server will allow the multiple requests needed to download the file in chunks. Don't know if requests are throttled.
                  • That the server still accepts the Range header like stated in the developer documenation

                  這篇關于C# - 以字節塊從 Google Drive 下載的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Ignore whitespace while reading XML(讀取 XML 時忽略空格)
                  XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                  Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標簽的 XML)
                  Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、單元格)
                  delete element from xml using LINQ(使用 LINQ 從 xml 中刪除元素)
                  Parse malformed XML(解析格式錯誤的 XML)

                    <small id='4fGdz'></small><noframes id='4fGdz'>

                        <tbody id='4fGdz'></tbody>

                        • <tfoot id='4fGdz'></tfoot>
                          • <bdo id='4fGdz'></bdo><ul id='4fGdz'></ul>
                          • <i id='4fGdz'><tr id='4fGdz'><dt id='4fGdz'><q id='4fGdz'><span id='4fGdz'><b id='4fGdz'><form id='4fGdz'><ins id='4fGdz'></ins><ul id='4fGdz'></ul><sub id='4fGdz'></sub></form><legend id='4fGdz'></legend><bdo id='4fGdz'><pre id='4fGdz'><center id='4fGdz'></center></pre></bdo></b><th id='4fGdz'></th></span></q></dt></tr></i><div class="kqc6wiw" id='4fGdz'><tfoot id='4fGdz'></tfoot><dl id='4fGdz'><fieldset id='4fGdz'></fieldset></dl></div>
                          • <legend id='4fGdz'><style id='4fGdz'><dir id='4fGdz'><q id='4fGdz'></q></dir></style></legend>
                            主站蜘蛛池模板: 强效碱性清洗剂-实验室中性清洗剂-食品级高纯氮气发生器-上海润榕科学器材有限公司 | 植筋胶-粘钢胶-碳纤维布-碳纤维板-环氧砂浆-加固材料生产厂家-上海巧力建筑科技有限公司 | 密集架|电动密集架|移动密集架|黑龙江档案密集架-大量现货厂家销售 | 博博会2021_中国博物馆及相关产品与技术博览会【博博会】 | 电机保护器-电动机综合保护器-上海硕吉电器有限公司 | 西安中国国际旅行社(西安国旅) | 贴片电容代理-三星电容-村田电容-风华电容-国巨电容-深圳市昂洋科技有限公司 | 上海单片机培训|重庆曙海培训分支机构—CortexM3+uC/OS培训班,北京linux培训,Windows驱动开发培训|上海IC版图设计,西安linux培训,北京汽车电子EMC培训,ARM培训,MTK培训,Android培训 | 方源木业官网-四川木门-全国木门专业品牌 | 生态板-实木生态板-生态板厂家-源木原作生态板品牌-深圳市方舟木业有限公司 | 固诺家居-全屋定制十大品牌_整体衣柜木门橱柜招商加盟 | 湖州织里童装_女童男童中大童装_款式多尺码全_织里儿童网【官网】-嘉兴嘉乐网络科技有限公司 | 气力输送设备_料封泵_仓泵_散装机_气化板_压力释放阀-河南锐驰机械设备有限公司 | 不锈钢管件(不锈钢弯头,不锈钢三通,不锈钢大小头),不锈钢法兰「厂家」-浙江志通管阀 | 德州网站开发定制-小程序开发制作-APP软件开发-「两山开发」 | 中国产业发展研究网 - 提供行业研究报告 可行性研究报告 投资咨询 市场调研服务 | 深圳货架厂_仓库货架公司_重型仓储货架_线棒货架批发-深圳市诺普泰仓储设备有限公司 | 雷蒙磨,雷蒙磨粉机,雷蒙磨机 - 巩义市大峪沟高峰机械厂 | 二手回收公司_销毁处理公司_设备回收公司-找回收信息网 | 丹佛斯变频器-Danfoss战略代理经销商-上海津信变频器有限公司 | 山东螺杆空压机,烟台空压机,烟台开山空压机-烟台开山机电设备有限公司 | 冷却塔厂家_冷却塔维修_冷却塔改造_凉水塔配件填料公司- 广东康明节能空调有限公司 | 骨龄仪_骨龄检测仪_儿童骨龄测试仪_品牌生产厂家【品源医疗】 | 长沙广告公司_制作,长沙喷绘_发光字_招牌制作_长沙泓润广告官网 长城人品牌官网 | 天津试验仪器-电液伺服万能材料试验机,恒温恒湿标准养护箱,水泥恒应力压力试验机-天津鑫高伟业科技有限公司 | 蔬菜配送公司|蔬菜配送中心|食材配送|饭堂配送|食堂配送-首宏公司 | 北京网站建设公司_北京网站制作公司_北京网站设计公司-北京爱品特网站建站公司 | IIS7站长之家-站长工具-爱网站请使用IIS7站长综合查询工具,中国站长【WWW.IIS7.COM】 | 冷油器,取样冷却器,热力除氧器-连云港振辉机械设备有限公司 | 气动隔膜泵-电动隔膜泵-循环热水泵-液下排污/螺杆/管道/化工泵「厂家」浙江绿邦 | 江苏南京多语种翻译-专业翻译公司报价-正规商务翻译机构-南京华彦翻译服务有限公司 | 超声波清洗机-超声波清洗设备定制生产厂家 - 深圳市冠博科技实业有限公司 | 浙江红酒库-冰雕库-气调库-茶叶库安装-医药疫苗冷库-食品物流恒温恒湿车间-杭州领顺实业有限公司 | 车充外壳,车载充电器外壳,车载点烟器外壳,点烟器连接头,旅行充充电器外壳,手机充电器外壳,深圳市华科达塑胶五金有限公司 | 南京技嘉环保科技有限公司-杀菌除臭剂|污水|垃圾|厕所|橡胶厂|化工厂|铸造厂除臭剂 | 北京工业设计公司-产品外观设计-产品设计公司-千策良品工业设计 北京翻译公司-专业合同翻译-医学标书翻译收费标准-慕迪灵 | 福兰德PVC地板|PVC塑胶地板|PVC运动地板|PVC商用地板-中国弹性地板系统专业解决方案领先供应商! 福建成考网-福建成人高考网 | 示波器高压差分探头-国产电流探头厂家-南京桑润斯电子科技有限公司 | TYPE-C厂家|TYPE-C接口|TYPE-C防水母座|TYPE-C贴片-深圳步步精 | 广东恩亿梯电源有限公司【官网】_UPS不间断电源|EPS应急电源|模块化机房|电动汽车充电桩_UPS电源厂家(恩亿梯UPS电源,UPS不间断电源,不间断电源UPS) | 环讯传媒,永康网络公司,永康网站建设,永康小程序开发制作,永康网站制作,武义网页设计,金华地区网站SEO优化推广 - 永康市环讯电子商务有限公司 |