GlobalDemo.DAL.Azure.StorageRepository.GetBlobURI C# (CSharp) Method

GetBlobURI() public method

Get a block blob's URI
public GetBlobURI ( string fileName, string containerName ) : Uri
fileName string The file name in storage
containerName string The container name
return System.Uri
        public Uri GetBlobURI(string fileName, string containerName)
        {            
            var client = _account.CreateCloudBlobClient();
            var container = client.GetContainerReference(containerName);
            var blob = container.GetBlockBlobReference(fileName);
            return blob.StorageUri.PrimaryUri;
        }

Usage Example

示例#1
0
        // This function will get triggered/executed when a new message is written 
        // on an Azure Queue called queue.
        public static async Task ProcessQueueMessage(
            [QueueTrigger("uploadqueue")] string message,
            TextWriter log)
        {
            log.WriteLineAsync(message).Wait();

            var m = message.Split(',');
            await log.WriteAsync("Message received: " + m);

            var model = new PhotoModel
            {
                ID = m[0],
                ServerFileName = m[1],
                StorageAccountName = m[2],
                Owner = m[3],
                OwnerName = m[4],
                BlobURL = m[5],
                OriginRegion = m[6]
            };

            //Copy blob from source to destination
            await log.WriteAsync("Replicating blob...");
            await Helpers.ReplicateBlobAsync(model, log);

            try
            {


                //Change the blob URL to point to the new location!    
                await log.WriteAsync("Getting blob URIs");
                string storageConnectionString = SettingsHelper.LocalStorageConnectionString;
                var repo = new StorageRepository(storageConnectionString);
                model.BlobURL = repo.GetBlobURI(model.ServerFileName, StorageConfig.PhotosBlobContainerName).ToString();
                model.ThumbnailURL = repo.GetBlobURI(model.ServerFileName, StorageConfig.ThumbnailsBlobContainerName).ToString();

                //Create thumbnail
                await log.WriteAsync("Creating thumbnail");
                await Helpers.CreateThumbnailAsync(repo, model.ServerFileName, log);

                //Store in table storage
                await log.WriteAsync("Saving to table storage");
                await Helpers.SaveToTableStorageAsync(model, log);

                //Add to Redis cache
                await log.WriteAsync("Saving to Redis");
                await Helpers.SaveToRedisAsync(model, log);
            }
            catch (Exception oops)
            {
                await log.WriteLineAsync(oops.Message);
            }
        }
All Usage Examples Of GlobalDemo.DAL.Azure.StorageRepository::GetBlobURI