Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure 如何将ADLS Gen-2的正文作为流传递_Azure_Rest_Filestream_Azure Data Lake - Fatal编程技术网

Azure 如何将ADLS Gen-2的正文作为流传递

Azure 如何将ADLS Gen-2的正文作为流传递,azure,rest,filestream,azure-data-lake,Azure,Rest,Filestream,Azure Data Lake,我正在使用ADLS Gen2路径更新API从已经创建的ADLS更新文件。 作为一个整体,我可以很容易地通过细绳,细绳工作良好,但同样的,细绳流不工作 我正在读取本地文件数据,并试图将其存储到流中并作为一个主体传递,但得到的Http请求头错误无效我有一个快速测试,下面的代码将本地文件读取为流,然后将流上载到adls gen2。它很好用。请在你身边试试,如果你有更多问题,请告诉我 static void Main(string[] args) {

我正在使用ADLS Gen2路径更新API从已经创建的ADLS更新文件。 作为一个整体,我可以很容易地通过细绳,细绳工作良好,但同样的,细绳流不工作


我正在读取本地文件数据,并试图将其存储到流中并作为一个主体传递,但得到的Http请求头错误无效

我有一个快速测试,下面的代码将本地文件读取为流,然后将流上载到adls gen2。它很好用。请在你身边试试,如果你有更多问题,请告诉我

        static void Main(string[] args)
        {                
            var auth = new AzureServiceTokenProvider();          

            const string url = "https://storage.azure.com/";
            string token = auth.GetAccessTokenAsync(url).Result;

            string requestUri = "https://xxx.dfs.core.windows.net/t11/b.txt?action=append&position=0";
            var method = new HttpMethod("PATCH");

            // read local file as stream
            var mystream = File.OpenRead(@"D:\temp\1\test1.txt");
            Console.WriteLine($"the stream length is: {mystream.Length}");
            Console.WriteLine($"the position of the stream is: {mystream.Position}");

            var stream_length = mystream.Length;

            var request = new HttpRequestMessage(method, requestUri)
            {
                //Content = new StringContent(upload_string)
                Content = new StreamContent(mystream)
            };

            // Add some defined headers
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain"));
            var i = request.Content.AsString().Length;
            Console.WriteLine(request.Content.AsString());

            var httpClient = new HttpClient();
            var result = httpClient.SendAsync(request).Result;

            Console.WriteLine("append result status code: "+ (int)result.StatusCode);

            //for flush    
            string requestUri_2 = "https://xxx.dfs.core.windows.net/t11/b.txt?action=flush&position="+stream_length;

            var request_2 = new HttpRequestMessage(method,requestUri_2);

            using (HttpClient httpClient_2 = new HttpClient())
            {
                httpClient_2.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                HttpResponseMessage response = httpClient_2.SendAsync(request_2).Result;
                Console.WriteLine("flush result status code: " + (int)response.StatusCode);
            }