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);
}