Azure SAS URLs are created here in AzureBlobStorage using:
if (includeUrl) {
string url = new Uri(_client.Uri, StoragePath.Normalize(fullPath)).ToString();
url += "?";
url += sas;
return url;
}
Typically, the _client.Uri will be something like https://myaccount.blob.core.windows.net/ or similar. However, when using Azurite, it's something like http://127.0.0.1:51256/devstoreaccount1/, with the devstoreaccount1 part being important.
In the function above, the fullPath should be something like container/name. However, StoragePath.Normalize is returning /container/name, and I don't understand why. This code here is doing it, removeTrailingSlash is false here:
return removeTrailingSlash
? path
: PathSeparatorString + path;
This makes no sense -- if "remove trailing slash" is false, the method.. prepends a slash? Also, given how this method is implemented, it's impossible for there to ever be a leading or trailing slash here. It splits the path by the separator with RemoveEmptyEntries and then recombines it.
All of this leads to the Uri() constructor stripping devstoreaccount1 from the base Uri. There's an additional subtle bug here -- connection strings for Azurite include a BlobEndpoint=http://127.0.0.1:51256/devstoreaccount1 (note lack of trailing slash). This works until a Uri constructor is used like the above -- Uri will strip off the last base path element if it doesn't end in a /.
Azure SAS URLs are created here in AzureBlobStorage using:
Typically, the
_client.Uriwill be something likehttps://myaccount.blob.core.windows.net/or similar. However, when using Azurite, it's something likehttp://127.0.0.1:51256/devstoreaccount1/, with thedevstoreaccount1part being important.In the function above, the fullPath should be something like
container/name. However,StoragePath.Normalizeis returning/container/name, and I don't understand why. This code here is doing it,removeTrailingSlashisfalsehere:This makes no sense -- if "remove trailing slash" is false, the method.. prepends a slash? Also, given how this method is implemented, it's impossible for there to ever be a leading or trailing slash here. It splits the path by the separator with
RemoveEmptyEntriesand then recombines it.All of this leads to the
Uri()constructor strippingdevstoreaccount1from the base Uri. There's an additional subtle bug here -- connection strings for Azurite include aBlobEndpoint=http://127.0.0.1:51256/devstoreaccount1(note lack of trailing slash). This works until a Uri constructor is used like the above -- Uri will strip off the last base path element if it doesn't end in a/.