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


C# CloudBlobContainer.GetBlockBlobReference方法代码示例

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


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

示例1: UploadPdfToBlob

        /// <summary>
        /// Upload the generated receipt Pdf to Blob storage.
        /// </summary>
        /// <param name="file">Byte array containig the Pdf file contents to be uploaded.</param>
        /// <param name="fileName">The desired filename of the uploaded file.</param>
        /// <returns></returns>
        public string UploadPdfToBlob(byte[] file, string fileName)
        {
            // Create the blob client.
            blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve a reference to a container.
            blobContainer = blobClient.GetContainerReference(receiptBlobName);

            // Create the container if it doesn't already exist.
            blobContainer.CreateIfNotExists(BlobContainerPublicAccessType.Blob);

            string fileUri = string.Empty;

            CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(fileName);

            using (var stream = new MemoryStream(file))
            {
                // Upload the in-memory Pdf file to blob storage.
                blockBlob.UploadFromStream(stream);
            }

            fileUri = blockBlob.Uri.ToString();

            return fileUri;
        }
开发者ID:kbxkb,项目名称:ContosoSportsLeague,代码行数:31,代码来源:AzureStorageMethods.cs

示例2: ParallelUploadFile

        public static void ParallelUploadFile(CloudBlobContainer blobContainer, string blobName, string filePath, string contentType = null)
        {
            var start = DateTime.Now;

              Console.WriteLine("\nUpload file in parallel.");
              CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(blobName);

              // 2M blocks for demo
              int blockLength = 2 * 1000 * 1024;
              byte[] dataToUpload = File.ReadAllBytes(filePath);
              int numberOfBlocks = (dataToUpload.Length / blockLength) + 1;
              string[] blockIds = new string[numberOfBlocks];

              Parallel.For(0, numberOfBlocks, x =>
              {
            var blockId = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
            var currentLength = Math.Min(blockLength, dataToUpload.Length - (x * blockLength));

            using (var memStream = new MemoryStream(dataToUpload, x * blockLength, currentLength))
            {
              blockBlob.PutBlock(blockId, memStream, null);
            }
            blockIds[x] = blockId;
            Console.WriteLine("BlockId:{0}", blockId);
              });

              if (!String.IsNullOrEmpty(contentType)) { blockBlob.Properties.ContentType = contentType; }
              blockBlob.PutBlockList(blockIds);
              Console.WriteLine("URL:{0}, ETag:{1}", blockBlob.Uri, blockBlob.Properties.ETag);

              var timespan = DateTime.Now - start;
              Console.WriteLine("{0} seconds.", timespan.Seconds);
        }
开发者ID:paulbouwer,项目名称:BlobStorageDemos,代码行数:33,代码来源:11_ParallelBlobUpload.cs

示例3: UploadFileToBlob

 public static void UploadFileToBlob(string fileName, string containerSAS)
 {
     Console.WriteLine("Uploading {0} to {1}", fileName, containerSAS);
     CloudBlobContainer container = new CloudBlobContainer(new Uri(containerSAS));
     CloudBlockBlob blob = container.GetBlockBlobReference(fileName);
     blob.UploadFromStream(new FileStream(fileName, FileMode.Open, FileAccess.Read));
 }
开发者ID:romitgirdhar,项目名称:azure-batch-samples,代码行数:7,代码来源:ImgProcUtils.cs

示例4: BlobFile

 /// <summary>
 /// Initializes a new instance of the <see cref="BlobFile" /> class.
 /// </summary>
 /// <param name="fileSystem">The file system.</param>
 /// <param name="address">The address.</param>
 /// <exception cref="ArgumentOutOfRangeException"/>
 /// <exception cref="ArgumentNullException"/>
 public BlobFile(BlobFileSystem fileSystem, INodeAddress address)
     : base(address, fileSystem)
 {
     _blobContainer = fileSystem.BlobClient.GetContainerReference(address.PathToDepth(1).Substring(1));
     _path = string.Join("/", Address.AbsolutePath.Split('/').Where((item, index) => index > 1));
     _blockBlob = _blobContainer.GetBlockBlobReference(_path);
 }
开发者ID:bradsjm,项目名称:DataflowPipe,代码行数:14,代码来源:BlobFile.cs

示例5: CreateBlobs

        public static List<string> CreateBlobs(CloudBlobContainer container, int count, BlobType type)
        {
            string name;
            List<string> blobs = new List<string>();
            for (int i = 0; i < count; i++)
            {
                switch (type)
                {
                    case BlobType.BlockBlob:
                        name = "bb" + Guid.NewGuid().ToString();
                        CloudBlockBlob blockBlob = container.GetBlockBlobReference(name);
                        blockBlob.PutBlockList(new string[] { });
                        blobs.Add(name);
                        break;

                    case BlobType.PageBlob:
                        name = "pb" + Guid.NewGuid().ToString();
                        CloudPageBlob pageBlob = container.GetPageBlobReference(name);
                        pageBlob.Create(0);
                        blobs.Add(name);
                        break;
                }
            }
            return blobs;
        }
开发者ID:huoxudong125,项目名称:azure-sdk-for-net,代码行数:25,代码来源:BlobTestBase.cs

示例6: GetBlob

 private CloudBlockBlob GetBlob(string path, CloudBlobContainer container = null)
 {
     container = container ?? GetContainer(path);
     var blobName = GetBlobName(path);
     var blob = container.GetBlockBlobReference(blobName);
     return blob;
 }
开发者ID:danludwig,项目名称:UCosmic,代码行数:7,代码来源:AzureBlobBinaryDataStorage.cs

示例7: ConfigurationFile

        public ConfigurationFile(CloudBlobContainer DeploymentContainer, string file)
        {
            //var config = DeploymentContainer.GetDirectoryReference("Configuration");
            init(DeploymentContainer.GetBlockBlobReference(file));

            //
        }
开发者ID:pksorensen,项目名称:C1AzureManager,代码行数:7,代码来源:ConfigurationFile.cs

示例8: CreateLogs

        public static List<string> CreateLogs(CloudBlobContainer container, StorageService service, int count, DateTime start, string granularity)
        {
            string name;
            List<string> blobs = new List<string>();

            for (int i = 0; i < count; i++)
            {
                CloudBlockBlob blockBlob;

                switch (granularity)
                {
                    case "hour":
                        name = string.Concat(service.ToString().ToLowerInvariant(), "/", start.AddHours(i).ToString("yyyy/MM/dd/HH", CultureInfo.InvariantCulture), "00/000001.log"); 
                        break;

                    case "day":
                        name = string.Concat(service.ToString().ToLowerInvariant(), "/", start.AddDays(i).ToString("yyyy/MM/dd/HH", CultureInfo.InvariantCulture), "00/000001.log"); 
                        break;

                    case "month":
                        name = string.Concat(service.ToString().ToLowerInvariant(), "/", start.AddMonths(i).ToString("yyyy/MM/dd/HH", CultureInfo.InvariantCulture), "00/000001.log"); 
                        break;

                    default:
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "CreateLogs granularity of '{0}' is invalid.", granularity));
                }

                blockBlob = container.GetBlockBlobReference(name);
                blockBlob.PutBlockList(new string[] { });
                blobs.Add(name);
            }

            return blobs;
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:34,代码来源:AnalyticsTestBase.cs

示例9: Main

        static void Main(string[] args)
        {
            string sas = "https://jamborstorage.blob.core.windows.net/sascontainer?sv=2014-02-14&sr=c&sig=HaD3DPQYd%2FQMJnuvYRafx0NuQQWSm0ZelODLxbyjEWI%3D&se=2014-09-03T09%3A43%3A28Z&sp=wl";
            CloudBlobContainer container = new CloudBlobContainer(new Uri(sas));

            //Create a list to store blob URIs returned by a listing operation on the container.
            List<Uri> blobUris = new List<Uri>();

            try
            {
                //Write operation: write a new blob to the container.
                CloudBlockBlob blob = container.GetBlockBlobReference("blobCreatedViaSAS.txt");
                string blobContent = "This blob was created with a shared access signature granting write permissions to the container. ";
                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();
            }
        }
开发者ID:JamborGit,项目名称:aspnet,代码行数:29,代码来源:Program.cs

示例10: InsertTodoItem

        private async Task InsertTodoItem(DataModel.TodoItem todoItem)
        {
            string errorString = string.Empty;

            if (media != null)
            {
                todoItem.ContainerName = "todoitemimages";
                todoItem.ResourceName = Guid.NewGuid().ToString();
            }

            await todoTable.InsertAsync(todoItem);

            if (!string.IsNullOrEmpty(todoItem.SasQueryString))
            {
                StorageCredentials cred = new StorageCredentials(todoItem.SasQueryString);
                var imageUri = new Uri(todoItem.ImageUri);

                CloudBlobContainer container = new CloudBlobContainer(
                    new Uri(string.Format("https://{0}/{1}",
                        imageUri.Host, todoItem.ContainerName)), cred);

                using (var inputStream = await media.OpenReadAsync())
                {
                    CloudBlockBlob blobFromSASCredential =
                        container.GetBlockBlobReference(todoItem.ResourceName);
                    await blobFromSASCredential.UploadFromStreamAsync(inputStream);
                }
                
                await ResetCaptureAsync();
            }

            items.Add(todoItem);
        }
开发者ID:cealmees,项目名称:Appdoptame,代码行数:33,代码来源:MainPage.xaml.cs

示例11: CreateBlobsAsync

        public static async Task<List<string>> CreateBlobsAsync(CloudBlobContainer container, int count, BlobType type)
        {
            string name;
            List<string> blobs = new List<string>();
            for (int i = 0; i < count; i++)
            {
                switch (type)
                {
                    case BlobType.BlockBlob:
                        name = "bb" + Guid.NewGuid().ToString();
                        CloudBlockBlob blockBlob = container.GetBlockBlobReference(name);
                        await blockBlob.PutBlockListAsync(new string[] { });
                        blobs.Add(name);
                        break;

                    case BlobType.PageBlob:
                        name = "pb" + Guid.NewGuid().ToString();
                        CloudPageBlob pageBlob = container.GetPageBlobReference(name);
                        await pageBlob.CreateAsync(0);
                        blobs.Add(name);
                        break;

                    case BlobType.AppendBlob:
                        name = "ab" + Guid.NewGuid().ToString();
                        CloudAppendBlob appendBlob = container.GetAppendBlobReference(name);
                        await appendBlob.CreateOrReplaceAsync();
                        blobs.Add(name);
                        break;
                }
            }
            return blobs;
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:32,代码来源:BlobTestBase.cs

示例12: GetBlobSasUri

        static string GetBlobSasUri(CloudBlobContainer container)
        {
            //Get a reference to a blob within the container.
            CloudBlockBlob blob = container.GetBlockBlobReference("sasblob.txt");

            //Upload text to the blob. If the blob does not yet exist, it will be created.
            //If the blob does exist, its existing content will be overwritten.
            string blobContent = "This blob will be accessible to clients via a Shared Access Signature.";
            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(blobContent));
            ms.Position = 0;
            using (ms)
            {
                blob.UploadFromStream(ms);
            }

            //Set the expiry time and permissions for the blob.
            //In this case the start time is specified as a few minutes in the past, to mitigate clock skew.
            //The shared access signature will be valid immediately.
            SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
            sasConstraints.SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-5);
            sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddHours(4);
            sasConstraints.Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write;

            //Generate the shared access signature on the blob, setting the constraints directly on the signature.
            string sasBlobToken = blob.GetSharedAccessSignature(sasConstraints);

            //Return the URI string for the container, including the SAS token.
            return blob.Uri + sasBlobToken;
        }
开发者ID:JamborGit,项目名称:aspnet,代码行数:29,代码来源:Program.cs

示例13: DownloadBlob

 public static void DownloadBlob(CloudBlobContainer container)
 {
     CloudBlockBlob blockBlob = container.GetBlockBlobReference("photo1.jpg");
     using (var fileStream = System.IO.File.OpenWrite(@"path\myfile"))
     {
         blockBlob.DownloadToStream(fileStream);
     }
 }
开发者ID:ftaran,项目名称:70-532,代码行数:8,代码来源:Program.cs

示例14: UploadFileWithContainerUri

        /// <summary>
        /// Upload files by using Container Uri
        /// </summary>
        /// <param name="sasUri"></param>
        /// <param name="localFilePath"></param>
        /// <param name="filePathInSyncFolder"></param>
        public bool UploadFileWithContainerUri(string sasUri, string localFilePath,
            string filePathInSyncFolder, string fileHashVaule, DateTime fileTimestamp, string eventType)
        {
            try
            {

                CloudBlobContainer container = new CloudBlobContainer(new Uri(sasUri));

                if (fileHashVaule == "isDirectory")
                {
                    CloudBlockBlob blob = container.GetBlockBlobReference(filePathInSyncFolder);
                    LocalFileSysAccess.LocalFileSys uploadfromFile = new LocalFileSysAccess.LocalFileSys();
                    uploadfromFile.uploadfromFilesystem(blob, localFilePath, eventType);
                    //blob.UploadFromFile(localFilePath, FileMode.Open);
                    //directory.Metadata["hashValue"] = fileHashVaule;

                }
                else
                {

                    CloudBlockBlob blob = container.GetBlockBlobReference(filePathInSyncFolder);
                    LocalFileSysAccess.LocalFileSys uploadfromFile = new LocalFileSysAccess.LocalFileSys();
                    uploadfromFile.uploadfromFilesystem(blob, localFilePath, eventType);

                    //blob.UploadFromFile(localFilePath, FileMode.Open);
                    blob.Metadata["hashValue"] = fileHashVaule;
                    blob.Metadata["timestamp"] = fileTimestamp.ToUniversalTime().ToString("MM/dd/yyyy HH:mm:ss");
                    blob.Metadata["filePath"] = filePathInSyncFolder;
                    //blob.Metadata["Deleted"] = "false";
                    blob.SetMetadata();
                    blob.CreateSnapshot();

                }

            }
            catch (Exception e)
            {
                Program.ClientForm.addtoConsole(e.ToString());
                Console.WriteLine(e.Message);
                //MessageBox.Show("-----------" + e.Message);
                return false;
            }

            return true;
        }
开发者ID:hangmiao,项目名称:DBLike,代码行数:51,代码来源:UploadFile.cs

示例15: getMetaData

 static void getMetaData(CloudBlobContainer container, string filename)
 {
     CloudBlockBlob blob = container.GetBlockBlobReference(filename);
     blob.FetchAttributes();
     foreach (var atr in blob.Metadata)
     {
         Console.WriteLine(atr.Key + " " + atr.Value);
     }
 }
开发者ID:leokraken,项目名称:dataservicessample,代码行数:9,代码来源:Program.cs


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