当前位置: 首页>>代码示例>>C#>>正文


C# CloudBlockBlob.UploadFromStream方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStream方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlockBlob.UploadFromStream方法的具体用法?C# CloudBlockBlob.UploadFromStream怎么用?C# CloudBlockBlob.UploadFromStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob的用法示例。


在下文中一共展示了CloudBlockBlob.UploadFromStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public static void Main(string[] args)
        {
            Console.WriteLine("Press any key to run sample...");
            Console.ReadKey();

            // Make sure the endpoint matches with the web role's endpoint.
            var tokenServiceEndpoint = ConfigurationManager.AppSettings["serviceEndpointUrl"];

            try
            {
                var blobSas = GetBlobSas(new Uri(tokenServiceEndpoint)).Result;

                // Create storage credentials object based on SAS
                var credentials = new StorageCredentials(blobSas.Credentials);

                // Using the returned SAS credentials and BLOB Uri create a block blob instance to upload
                var blob = new CloudBlockBlob(blobSas.BlobUri, credentials);

                using (var stream = GetFileToUpload(10))
                {
                    blob.UploadFromStream(stream);
                }

                Console.WriteLine("Blob uplodad successful: {0}", blobSas.Name);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            
            Console.WriteLine();
            Console.WriteLine("Done. Press any key to exit...");
            Console.ReadKey();
        }
开发者ID:mspnp,项目名称:cloud-design-patterns,代码行数:34,代码来源:Program.cs

示例2: Run

        public void Run()
        {
            var storageAccount = CloudStorageAccount.Parse(_storageConnectionString);
            var blobClient = storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference("mycontainer");
            container.CreateIfNotExists();
            _blob = container.GetBlockBlobReference("myblob.txt");
            if (!_blob.Exists())
            {
                using (var s = new MemoryStream())
                {
                    _blob.UploadFromStream(s);
                }
            }

            Task.Factory.StartNew(() => GenerateContentAsync());
            Task.Factory.StartNew(() => AppendStreamToBlobAsync());
            Task.WaitAll();
        }
开发者ID:GitAllen,项目名称:TestCode,代码行数:19,代码来源:BlobAppender.cs

示例3: OnExecuting

        protected override void OnExecuting(CloudBlockBlob workItem)
        {
            if (workItem == null)
                throw new ArgumentNullException("workItem");

            if (workItem.Metadata.ContainsKey(CompressedFlag))
                return;

            using (var blobStream = new MemoryStream())
            {
                workItem.DownloadToStream(blobStream);

                using (var compressedStream = new MemoryStream())
                {
                    CompressStream(compressedStream, blobStream);

                    SetCompressedFlag(workItem);

                    workItem.UploadFromStream(compressedStream);
                }
            }
        }
开发者ID:hossamdarwish,项目名称:Brisebois.WindowsAzure,代码行数:22,代码来源:BlobCompressor.cs

示例4: UploadBlobStream

 /// <summary>
 /// Uploads Memory Stream to Blob
 /// </summary>
 /// <param name="outputBlob"></param>
 /// <param name="line"></param>
 private static void UploadBlobStream(CloudBlockBlob outputBlob, string line)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         if (outputBlob.Exists())
         {
             outputBlob.DownloadToStream(ms);
         }
         byte[] dataToWrite = Encoding.UTF8.GetBytes(line + "\r\n");
         ms.Write(dataToWrite, 0, dataToWrite.Length);
         ms.Position = 0;
         outputBlob.UploadFromStream(ms);
     }
 }
开发者ID:CarlRabeler,项目名称:WingTipTickets,代码行数:19,代码来源:DataGenerator.cs

示例5: UploadBlobInParallel

 void UploadBlobInParallel(CloudBlockBlob blob, Stream stream)
 {
     blob.ServiceClient.ParallelOperationThreadCount = NumberOfIOThreads;
     container.ServiceClient.RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(BackOffInterval), MaxRetries);
     blob.StreamWriteSizeInBytes = BlockSize;
     blob.UploadFromStream(stream);
 }
开发者ID:jberke,项目名称:NServiceBus.Azure,代码行数:7,代码来源:BlobStorageDataBus.cs

示例6: UploadBlob

        private static void UploadBlob(CloudBlockBlob blob, RepositoryEntity obj)
        {
            using (var streamCompressed = new MemoryStream())
            {
                using (var gzip = new GZipStream(streamCompressed, CompressionMode.Compress))
                {
                    var data = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
                    gzip.Write(data, 0, data.Length);
                    gzip.Flush();
                    gzip.Close();

                    using (var streamOut = new MemoryStream(streamCompressed.ToArray()))
                    {
                        blob.UploadFromStream(streamOut);
                    }
                }
            }
        }
开发者ID:postworthy,项目名称:postworthy,代码行数:18,代码来源:Program.cs

示例7: UploadPicture

 private static void UploadPicture(CloudBlockBlob blob, String path)
 {
     blob.Properties.ContentType = "image/jpeg";
     using (var fileStream = File.OpenRead(path))
     {
         blob.UploadFromStream(fileStream);
     }
 }
开发者ID:PeLoSTA,项目名称:Wpf_Cloud_01_Blobs,代码行数:8,代码来源:MainWindow.xaml.cs

示例8: UploadBlockBlob

 public virtual void UploadBlockBlob(CloudBlockBlob blockBlob, Stream streamToUpload, AccessCondition accessCondition = null)
 {
     blockBlob.UploadFromStream(streamToUpload, accessCondition);
 }
开发者ID:jjschlesinger,项目名称:DefiantCode.Components,代码行数:4,代码来源:CloudBlobManager.cs

示例9: uploadButton_Click

        protected void uploadButton_Click(object sender, EventArgs e)
        {
            if (photoUpload.HasFile)
            {
                string fullFileName = photoUpload.PostedFile.FileName;
                string shortFileName = Path.GetFileName(fullFileName);

                blockBlob = blobContainer.GetBlockBlobReference(shortFileName + DateTime.Now);

                using (var fileStream = System.IO.File.OpenRead(fullFileName))
                {
                    blockBlob.UploadFromStream(fileStream);
                }

                profileImage.ImageUrl = blockBlob.Uri.ToString();
            }
        }
开发者ID:anthony-salutari,项目名称:Book-Store,代码行数:17,代码来源:CreateAccount.aspx.cs

示例10: UploadBlob

        /// <summary>
        /// Uploads the BLOB.
        /// </summary>
        /// <param name="blob">The BLOB.</param>
        /// <param name="dataBytes">The data bytes.</param>
        /// <param name="metaData">The meta data.</param>
        /// <returns>System.String for ETag.</returns>
        public static string UploadBlob(CloudBlockBlob blob, byte[] dataBytes, IDictionary<string, string> metaData)
        {
            try
            {
                if (metaData != null)
                {
                    foreach (var key in metaData.Keys)
                    {
                        blob.Metadata.Merge(key, metaData[key]);
                    }
                }

                using (var msWrite = new MemoryStream(dataBytes))
                {
                    msWrite.Position = 0;
                    blob.UploadFromStream(msWrite);
                }

                return blob.Properties.ETag;
            }
            catch (Exception ex)
            {
                throw ex.Handle("UploadBlob", new { blob = blob.Uri.ToString(), metaData = metaData });
            }
        }
开发者ID:rynnwang,项目名称:CommonSolution,代码行数:32,代码来源:AzureStorageManager.cs

示例11: UploadFromStream

 private void UploadFromStream(CloudBlockBlob blob, Stream source)
 {
     try
     {
         blob.UploadFromStream(source);
     }
     catch (StorageException e)
     {
         throw new BlobException(string.Format(CultureInfo.InvariantCulture, "Could not UploadFromStream to blob named '{0}' in container.  See inner exception for details.", blob.Name), e);
     }
 }
开发者ID:modulexcite,项目名称:StudentSuccessDashboard,代码行数:11,代码来源:AzureBlobContainer.cs

示例12: UploadBlobInParallel

 private void UploadBlobInParallel(CloudBlockBlob blob, Stream stream)
 {
     try
     {
         blob.ServiceClient.ParallelOperationThreadCount = NumberOfIOThreads;
         blob.UploadFromStream(stream);
     }
     catch (StorageException ex)
     {
          logger.Warn(ex.Message);
     }
 }
开发者ID:afyles,项目名称:NServiceBus,代码行数:12,代码来源:BlobStorageDataBus.cs

示例13: UseBlobSAS

        static void UseBlobSAS(string sas)
        {
            //Try performing blob operations using the SAS provided.

            //Return a reference to the blob using the SAS URI.
            CloudBlockBlob blob = new CloudBlockBlob(new Uri(sas));

            //Write operation: Write a new blob to the container. 
            try
            {
                string blobContent = "This blob was created with a shared access signature granting write permissions to the blob. ";
                MemoryStream msWrite = new MemoryStream(Encoding.UTF8.GetBytes(blobContent));
                msWrite.Position = 0;
                using (msWrite)
                {
                    blob.UploadFromStream(msWrite);
                }
                Console.WriteLine("Write operation succeeded for SAS " + sas);
                Console.WriteLine();
            }
            catch (StorageException e)
            {
                Console.WriteLine("Write operation failed for SAS " + sas);
                Console.WriteLine("Additional error information: " + e.Message);
                Console.WriteLine();
            }

            //Read operation: Read the contents of the blob.
            try
            {
                MemoryStream msRead = new MemoryStream();
                using (msRead)
                {
                    blob.DownloadToStream(msRead);
                    msRead.Position = 0;
                    using (StreamReader reader = new StreamReader(msRead, true))
                    {
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            Console.WriteLine(line);
                        }
                    }
                }
                Console.WriteLine("Read operation succeeded for SAS " + sas);
                Console.WriteLine();
            }
            catch (StorageException e)
            {
                Console.WriteLine("Read operation failed for SAS " + sas);
                Console.WriteLine("Additional error information: " + e.Message);
                Console.WriteLine();
            }

            //Delete operation: Delete the blob.
            try
            {
                blob.Delete();
                Console.WriteLine("Delete operation succeeded for SAS " + sas);
                Console.WriteLine();
            }
            catch (StorageException e)
            {
                Console.WriteLine("Delete operation failed for SAS " + sas);
                Console.WriteLine("Additional error information: " + e.Message);
                Console.WriteLine();
            }
        }
开发者ID:faiyaz-shaik,项目名称:Prototypes,代码行数:68,代码来源:Program.cs

示例14: TestEventsHelper

        public void TestEventsHelper(CloudBlockBlob blob, int bufferSize, int expectedSending, int expectedResponseReceived, int expectedRequestComplete, int expectedRetry, bool testRetry)
        {
            byte[] buffer = GetRandomBuffer(bufferSize);

            BlobRequestOptions blobOptions = new BlobRequestOptions();
            blobOptions.SingleBlobUploadThresholdInBytes = EventFiringTests.SingleBlobUploadThresholdInBytes;
            blobOptions.RetryPolicy = new OldStyleAlwaysRetry(new TimeSpan(1), maxRetries);
            int sendingRequestFires = 0;
            int responseReceivedFires = 0;
            int requestCompleteFires = 0;
            int retryFires = 0;

            OperationContext.GlobalSendingRequest += (sender, args) => sendingRequestFires++;
            OperationContext.GlobalResponseReceived += (sender, args) => responseReceivedFires++;
            OperationContext.GlobalRequestCompleted += (sender, args) => requestCompleteFires++;
            OperationContext.GlobalRetrying += (sender, args) => retryFires++;

            if (testRetry)
            {
                using (MemoryStream wholeBlob = new MemoryStream())
                {
                    try
                    {
                        blob.DownloadToStream(wholeBlob, null, blobOptions, null);
                    }
                    catch (StorageException e)
                    {
                        Assert.AreEqual(404, e.RequestInformation.HttpStatusCode);
                    }
                }
            }
            else
            {
                using (MemoryStream wholeBlob = new MemoryStream(buffer))
                {
                    blob.UploadFromStream(wholeBlob, null, blobOptions, null);
                }
            }

            Assert.AreEqual(expectedSending, sendingRequestFires);
            Assert.AreEqual(expectedResponseReceived, responseReceivedFires);
            Assert.AreEqual(expectedRequestComplete, requestCompleteFires);
            Assert.AreEqual(expectedRetry, retryFires);
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:44,代码来源:EventFiringTests.cs

示例15: UploadDocument

 private static void UploadDocument(CloudBlockBlob blob, String path)
 {
     using (var fileStream = File.OpenRead(path))
     {
         blob.UploadFromStream(fileStream);
     }
 }
开发者ID:PeLoSTA,项目名称:Wpf_Cloud_01_Blobs,代码行数:7,代码来源:MainWindow.xaml.cs


注:本文中的Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。