Upload a file to Azure Blob Storage
with the original filename and also assign the filename as meta-data
to the CloudBlob
These characters are not permitted in the meta-data
but are acceptable as the blob
name:
š Š ñ Ñ ç Ç ÿ Ÿ ž Ž Ð œ Œ « » éèëêð ÉÈËÊ àâä ÀÁÂÃÄÅ àáâãäå ÙÚÛÜ ùúûüµ òóôõöø ÒÓÔÕÖØ ìíîï ÌÍÎÏ
meta-data
? Are we missing some setting that causes this exception?blob
and meta-data
naming conventions, but none about the data itself!var dirtyFileName = file.FileName;
var normalizedFileName = file.FileName.CleanOffDiacriticAndNonASCII();
// Blob name accepts almost characters that are acceptable as filenames in Windows
var blob = container.GetBlobReference(dirtyFileName);
//Upload content to the blob, which will create the blob if it does not already exist.
blob.Metadata["FileName"] = normalizedFileName;
blob.Attributes.Properties.ContentType = file.ContentType;
// ERROR: Occurs here!
blob.UploadFromStream(file.InputStream);
blob.SetMetadata();
blob.SetProperties();
Illegal characters in filename is only the tip of the ice-berg, magnified only for the purpose of this question! The bigger picture is that we index these files using Lucene.net
and as such need a lot of meta-data
to be stored on the blob
. Please don't suggest storing it all separately in a database, just don't! Up until now we have been lucky to only have come across one file with diacritic characters!
So, at the moment we are making the effort to avoid saving the filename in the meta-data
as a workaround!
Just have had confirmation from the azure-sdk-for-net
team on GitHub that only ASCII
characters are valid as data within blob meta-data
.
joeg commented:
The supported characters in the blob metadata must be ASCII characters. To work around this you can either escape the string ( percent encode), base64 encode etc.
So as a work-around, either: