久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='zNFHy'></tfoot>

      <small id='zNFHy'></small><noframes id='zNFHy'>

    1. <legend id='zNFHy'><style id='zNFHy'><dir id='zNFHy'><q id='zNFHy'></q></dir></style></legend>

      • <bdo id='zNFHy'></bdo><ul id='zNFHy'></ul>

    2. <i id='zNFHy'><tr id='zNFHy'><dt id='zNFHy'><q id='zNFHy'><span id='zNFHy'><b id='zNFHy'><form id='zNFHy'><ins id='zNFHy'></ins><ul id='zNFHy'></ul><sub id='zNFHy'></sub></form><legend id='zNFHy'></legend><bdo id='zNFHy'><pre id='zNFHy'><center id='zNFHy'></center></pre></bdo></b><th id='zNFHy'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zNFHy'><tfoot id='zNFHy'></tfoot><dl id='zNFHy'><fieldset id='zNFHy'></fieldset></dl></div>

        RestSharp AddFile 使用 Stream

        RestSharp AddFile Using Stream(RestSharp AddFile 使用 Stream)

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

              • <bdo id='0vhrW'></bdo><ul id='0vhrW'></ul>
              • <small id='0vhrW'></small><noframes id='0vhrW'>

                  <tbody id='0vhrW'></tbody>

                <legend id='0vhrW'><style id='0vhrW'><dir id='0vhrW'><q id='0vhrW'></q></dir></style></legend>
              • <tfoot id='0vhrW'></tfoot>
                  本文介紹了RestSharp AddFile 使用 Stream的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我正在使用 RestSharp(Visual Studio 2013 中的版本 105.2.3.0,.net 4.5)來調用 NodeJS 托管的 Web 服務.我需要撥打的電話之一是上傳文件.使用 RESTSharp 請求,如果我將流從我的一端檢索到一個字節數組中并將其傳遞給 AddFile,它就可以正常工作.但是,我更愿意流式傳輸內容,而不是將整個文件加載到服務器內存中(文件可以是 100 MB).

                  I am using RestSharp (version 105.2.3.0 in Visual Studio 2013, .net 4.5) to call a NodeJS hosted webservice. One of the calls I need to make is to upload a file. Using a RESTSharp request, if I retrieve the stream from my end into a byte array and pass that to AddFile, it works fine. However, I would much rather stream the contents and not load up entire files in server memory (the files can be 100's of MB).

                  如果我設置了一個操作來復制我的流(見下文),我會在 System.Net.ProtocolViolationException 的MyStream.CopyTo"行出現異常(要寫入流的字節超過 Content-Length 字節指定的大小).在調用 client.Execute 后,此異常會在 Action 塊內引發.

                  If I set up an Action to copy my stream (see below), I get an exception at the "MyStream.CopyTo" line of System.Net.ProtocolViolationException (Bytes to be written to the stream exceed the Content-Length bytes size specified). This exception is thrown within the Action block after client.Execute is called.

                  根據我的閱讀,我不應該手動添加 Content-Length 標頭,如果我這樣做也無濟于事.我嘗試將 CopyTo 緩沖區設置得太小和太大,以及完全忽略它,但無濟于事.有人可以告訴我我錯過了什么嗎?

                  From what I read, I should not be manually adding a Content-Length header, and it doesn't help if I do. I have tried setting CopyTo buffer too small and large values, as well as omitting it entirely, to no avail. Can somebody give me a hint on what I've missed?

                      // Snippet...
                      protected T PostFile<T>(string Resource, string FieldName, string FileName,
                          string ContentType, Stream MyStream, 
                          IEnumerable<Parameter> Parameters = null) where T : new()
                      {
                          RestRequest request = new RestRequest(Resource);
                          request.Method = Method.POST;
                  
                          if (Parameters != null)
                          {
                              // Note:  parameters are all UrlSegment values
                              request.Parameters.AddRange(Parameters);
                          }
                  
                          // _url, _username and _password are defined configuration variables
                          RestClient client = new RestClient(_url);
                          if (!string.IsNullOrEmpty(_username))
                          {
                              client.Authenticator = new HttpBasicAuthenticator(_username, _password);
                          }
                  
                          /*
                          // Does not work, throws System.Net.ProtocolViolationException,
                          // Bytes to be written to the stream exceed the 
                          // Content-Length bytes size specified.
                          request.AddFile(FieldName, (s) =>
                          {
                              MyStream.CopyTo(s);
                              MyStream.Flush();
                          }, FileName, ContentType);
                          */
                  
                          // This works, but has to load the whole file in memory
                          byte[] data = new byte[MyStream.Length];
                          MyStream.Read(data, 0, (int) MyStream.Length);
                          request.AddFile(FieldName, data, FileName, ContentType);
                  
                          var response = client.Execute<T>(request);
                  
                          // check response and continue...
                      }
                  

                  推薦答案

                  我也遇到了同樣的問題.我最終在 Files 集合上使用了 .Add() .它有一個與 AddFile() 具有相同參數的 FileParameter 參數,您只需添加 ContentLength:

                  I had the same issue. I ended up using the .Add() on the Files collection. It has a FileParameter param which has the same params as AddFile(), you just have to add the ContentLength:

                  var req = GetRestRequest("Upload", Method.POST, null);
                  //req.AddFile("file",
                  //    (s) => {
                  //        var stream = input(imageObject);
                  //        stream.CopyTo(s);
                  //        stream.Dispose();
                  //    },
                  //    fileName, contentType);
                  
                  req.Files.Add(new FileParameter {
                      Name = "file",
                      Writer = (s) => {
                          var stream = input(imageObject);
                          stream.CopyTo(s);
                          stream.Dispose();
                      },
                      FileName = fileName,
                      ContentType = contentType,
                      ContentLength = contentLength
                  });            
                  

                  這篇關于RestSharp AddFile 使用 Stream的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                  onClick event for Image in Unity(Unity中圖像的onClick事件)
                  Running Total C#(運行總 C#)
                  Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時刪除目錄)
                  asp.net listview highlight row on click(asp.net listview 在單擊時突出顯示行)
                  Calling A Button OnClick from a function(從函數調用按鈕 OnClick)
                    <tbody id='gYcfQ'></tbody>
                  • <bdo id='gYcfQ'></bdo><ul id='gYcfQ'></ul>

                        <small id='gYcfQ'></small><noframes id='gYcfQ'>

                            <legend id='gYcfQ'><style id='gYcfQ'><dir id='gYcfQ'><q id='gYcfQ'></q></dir></style></legend>
                          • <i id='gYcfQ'><tr id='gYcfQ'><dt id='gYcfQ'><q id='gYcfQ'><span id='gYcfQ'><b id='gYcfQ'><form id='gYcfQ'><ins id='gYcfQ'></ins><ul id='gYcfQ'></ul><sub id='gYcfQ'></sub></form><legend id='gYcfQ'></legend><bdo id='gYcfQ'><pre id='gYcfQ'><center id='gYcfQ'></center></pre></bdo></b><th id='gYcfQ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='gYcfQ'><tfoot id='gYcfQ'></tfoot><dl id='gYcfQ'><fieldset id='gYcfQ'></fieldset></dl></div>

                            <tfoot id='gYcfQ'></tfoot>

                            主站蜘蛛池模板: 97国产精品| 久久精品成人一区 | 日本精品在线一区 | 在线不卡视频 | 亚洲美女网站 | 欧美日韩国产高清视频 | 黄片毛片在线观看 | 精品1区2区3区| 日韩欧美一区二区三区免费观看 | 亚洲精品中文字幕 | 一区二区小视频 | 国产99久久精品一区二区永久免费 | 欧美一级免费 | 毛片韩国| 午夜免费观看网站 | 国产精品久久 | 久久久久国产一区二区三区四区 | 精品中文字幕久久 | 欧美日韩精品专区 | 日本黄色大片免费 | 亚洲网在线| 亚洲一区二区三区在线 | 久久国内精品 | av成年人网站| 日韩在线小视频 | 51ⅴ精品国产91久久久久久 | 伊人国产精品 | 亚洲人a | 黑人久久久 | 少妇精品久久久久久久久久 | 久久精品久久精品 | 三级黄色片在线 | 99在线视频观看 | 国产一区二区av | 亚洲精品一二三区 | 国产精品成人品 | 日本天天操 | 欧美一区免费 | 久久在线视频 | 国产精品久久久久久久久免费樱桃 | 成人网址在线观看 |