I'm trying to add images to Azure blob storage, (this part of the program works correctly).
Once each image is in the blob storage I want to create an Azure storage table with an entity having two columns. The image category, and the image URI.
When I try to insert into the Azure Storage Table the application enters "break mode".
Ultimately this will be used by a mobile app that uses the table to select image URIs as the imagesource for a grid view so I need the full URI.
I've hardcoded the category to try and narrow down the problem.
I'm using the Azure Storage Emulator during development. FYI.
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Queue;
using Microsoft.WindowsAzure.Storage.Table;
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace AzureEmulatorTests
{
class Program
{
static async Task Main(string[] args)
{
const string localPath = "./data/";
const string containerName = "mycontainer";
const string tableName = "mytable";
var storageAccount = CloudStorageAccount.Parse(@"UseDevelopmentStorage=true");
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(containerName);
await container.CreateIfNotExistsAsync();
var tableClient = storageAccount.CreateCloudTableClient();
var table = tableClient.GetTableReference(tableName);
await table.CreateIfNotExistsAsync();
string[] filenames = Directory.GetFiles(localPath);
foreach (var images in filenames)
{
string _imageBlobReference = Guid.NewGuid() + ".jpg";
var blob = container.GetBlockBlobReference(_imageBlobReference);
await blob.UploadFromFileAsync(images);
string blobUrl = blob.Uri.AbsoluteUri;
ImageFile image = new ImageFile("Birthday", blobUrl);
await table.ExecuteAsync(TableOperation.Insert(image));
}
Console.WriteLine("Files Uploaded... Press any key to continue.");
Console.ReadKey();
}
}
class ImageFile : TableEntity
{
public ImageFile(string Category, string ImageURL)
{
PartitionKey = Category;
RowKey = ImageURL;
}
}
}
The solution I found is to not put the URL in the PartitionKey or Rowkey properties.
When I added a string property to the table, I was able to add the URL without issue.