public GetBlobURI ( string fileName, string containerName ) : |
||
fileName | string | The file name in storage |
containerName | string | The container name |
return |
// 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); } }
public IHttpActionResult Get(string extension) { Regex rg = new Regex(@"^[a-zA-Z0-9]{1,3}$"); if(!rg.IsMatch(extension)) { throw new HttpResponseException(System.Net.HttpStatusCode.BadRequest); } string connectionString = SettingsHelper.LocalStorageConnectionString; var account = CloudStorageAccount.Parse(connectionString); StorageRepository repo = new StorageRepository(account); //Get the SAS token for the container. Allow writes for 2 minutes var sasToken = repo.GetBlobContainerSASToken(); //Get the blob so we can get the full path including container name var id = Guid.NewGuid().ToString(); var newFileName = id + "." + extension; string blobURL = repo.GetBlobURI( newFileName, DAL.Azure.StorageConfig.UserUploadBlobContainerName).ToString(); //This function determines which storage account the blob will be //uploaded to, enabling the future possibility of sharding across //multiple storage accounts. var client = account.CreateCloudBlobClient(); var response = new StorageResponse { ID = id, StorageAccountName = client.BaseUri.Authority.Split('.')[0], BlobURL = blobURL, BlobSASToken = sasToken, ServerFileName = newFileName }; return Ok(response); }