Beispiel #1
0
        public void TestCloudFileToFileStream()
        {
            Uri uri  = new Uri($"https://4wkg2mcjiyss43.file.core.windows.net/temp/x.zip");
            var dest = File.OpenWrite(@".\x.zip");
            var cfg  = new ConfigurationBuilder()
                       .AddJsonFile("appsettings.json", true)
                       .AddXmlFile("appsettings.xml", true)
                       .Build();
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(cfg["x:y:a:x"]);
            IStorageItem        f = uri.CreateItem();

            f.CopyToStream(dest, false);

            byte[] srcbytes = null;
            using (MemoryStream ms = new MemoryStream())
            {
                (new CloudFile(uri, storageAccount.Credentials)).DownloadToStreamAsync(ms).GetAwaiter().GetResult();
                srcbytes = ms.ToArray();
            }
            byte[] destbytes = File.ReadAllBytes(@".\x.zip");
            Assert.Equal(Convert.ToBase64String(srcbytes), Convert.ToBase64String(destbytes));
        }