Upload a file to Azure Blob Storage
with the original filename and also assign the filename as meta-data
to the CloudBlob
To expand on the answer by bPratik, we've found that Base64 encoding metadata works nicely. We use this extension method to do the encode and decode:
public static class Base64Extensions
{
public static string ToBase64(this string input)
{
var bytes = Encoding.UTF8.GetBytes(input);
return Convert.ToBase64String(bytes);
}
public static string FromBase64(this string input)
{
var bytes = Convert.FromBase64String(input);
return Encoding.UTF8.GetString(bytes);
}
}
and then when setting blob metadata:
blobReference.Metadata["Filename"] = filename.ToBase64();
and when retrieving it:
var filename = blobReference.Metadata["Filename"].FromBase64();
For search, you would have to decode the filename before presenting it to the indexer, or use the blob's actual filename assuming you're still using the original filename there.