OpenWrite() public method

Opens a stream for writing to the blob.
public OpenWrite ( ) : Microsoft.WindowsAzure.StorageClient.BlobStream
return Microsoft.WindowsAzure.StorageClient.BlobStream
コード例 #1
0
ファイル: AzureBlob.cs プロジェクト: nickchal/pash
		private static void UploadBlobStream(CloudBlob blob, string sourceFile)
		{
			FileStream fileStream = File.OpenRead(sourceFile);
			using (fileStream)
			{
				byte[] numArray = new byte[0x20000];
				BlobStream blobStream = blob.OpenWrite();
				using (blobStream)
				{
					blobStream.BlockSize = (long)0x20000;
					while (true)
					{
						int num = fileStream.Read(numArray, 0, (int)numArray.Length);
						if (num <= 0)
						{
							break;
						}
						blobStream.Write(numArray, 0, num);
					}
				}
			}
		}
コード例 #2
0
        private static void UploadBlobStream(CloudBlob blob, string sourceFile)
        {
            using (FileStream readStream = File.OpenRead(sourceFile))
            {
                byte[] buffer = new byte[1024 * 128];

                using (BlobStream blobStream = blob.OpenWrite())
                {
                    blobStream.BlockSize = 1024 * 128;

                    while (true)
                    {
                        int bytesCount = readStream.Read(buffer, 0, buffer.Length);

                        if (bytesCount <= 0)
                        {
                            break;
                        }

                        blobStream.Write(buffer, 0, bytesCount);
                    }
                }
            }
        }
コード例 #3
0
        static long WriteWithoutCompression(CloudBlob blob, BlobRequestOptions mapped, Action<Stream> writer)
        {
            var md5 = MD5.Create();
            long position;
            using (var stream = blob.OpenWrite(mapped))
            {
                using (var crypto = new CryptoStream(stream, md5, CryptoStreamMode.Write))
                {
                    writer(crypto);
                }

                position = stream.Position;
            }
            blob.Metadata[LokadHashFieldName] = Convert.ToBase64String(md5.Hash);
            blob.SetMetadata();
            return position;
        }
コード例 #4
0
 static long WriteWithCompression(CloudBlob blob, BlobRequestOptions mapped, Action<Stream> writer)
 {
     long position;
     var md5 = MD5.Create();
     blob.Properties.ContentEncoding = "gzip";
     using (var stream = blob.OpenWrite(mapped))
     {
         using (var crypto = new CryptoStream(stream, md5, CryptoStreamMode.Write))
         using (var compress = new GZipStream(crypto, CompressionMode.Compress, true))
         {
             writer(compress);
         }
         position = stream.Position;
     }
     blob.Metadata[LokadHashFieldName] = Convert.ToBase64String(md5.Hash);
     blob.SetMetadata();
     return position;
 }
コード例 #5
0
        public static void UploadBlobFile(byte[] fileBytes, string fileName)
        {
            try
            {
                string storageAccountConnection = string.Empty;

                storageAccountConnection = ConfigurationManager.AppSettings["StorageAccount.ConnectionString"].ToString();

                // If you want to use Windows Azure cloud storage account, use the following
                // code (after uncommenting) instead of the code above.
                cloudStorageAccount = CloudStorageAccount.Parse(storageAccountConnection);

                // Create the blob client, which provides
                // authenticated access to the Blob service.
                blobClient = cloudStorageAccount.CreateCloudBlobClient();

                string deploymentPackageFolderString = string.Empty;

                deploymentPackageFolderString = ConfigurationManager.AppSettings["DeploymentPackageFolder"].ToString();

                // Get the container reference.
                blobContainer = blobClient.GetContainerReference(deploymentPackageFolderString);

                // Create the container if it does not exist.
                blobContainer.CreateIfNotExist();

                // Set permissions on the container.
                containerPermissions = new BlobContainerPermissions();

                // This sample sets the container to have public blobs. Your application
                // needs may be different. See the documentation for BlobContainerPermissions
                // for more information about blob container permissions.
                containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;

                blobContainer.SetPermissions(containerPermissions);

                blob = blobContainer.GetBlobReference(fileName);

                // Open a stream using the cloud object
                using (BlobStream blobStream = blob.OpenWrite())
                {
                    blobStream.Write(fileBytes, 0, fileBytes.Count());

                    blobStream.Flush();

                    blobStream.Close();
                }
            }
            catch (System.Exception ex)
            {
                Logger.Write(string.Format("Error in UploadBlobFile()  Error: {0}", ex.Message));
            }
        }