當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。