I am upgrading Azure Storage from 1.7 SDK to 2.3 SDK and have been updating my GetBlobReference(string)
calls to GetBlockReferenceFromServer(Uri)
In the past I have been using relative URIs, but when I pass these through to GetBlockReferenceFromServer
I get an error that says I cannot use absolute URIs (see stack below)
Sample code:
Dim myAccount As CloudStorageAccount = CloudStorageAccount.Parse(connectionString)
Dim myClient As CloudBlobClient = myAccount.CreateCloudBlobClient()
Dim myRelativeUri As New Uri("mycontainer/myblob.txt", UriKind.Relative)
Dim myBlobref As ICloudBlob = myClient.GetBlobReferenceFromServer(myRelativeUri) <- Errors on this line
Error stack:
System.ArgumentException: Address 'mycontainer/myblob.txt' is a relative address. Only absolute addresses are permitted.Parameter name: uri
at Microsoft.WindowsAzure.Storage.StorageUri.AssertAbsoluteUri(Uri uri)
at Microsoft.WindowsAzure.Storage.StorageUri.set_PrimaryUri(Uri value)
at Microsoft.WindowsAzure.Storage.StorageUri..ctor(Uri primaryUri, Uri secondaryUri)
at Microsoft.WindowsAzure.Storage.StorageUri..ctor(Uri primaryUri)
at Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetBlobReferenceFromServer(Uri blobUri, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext) at MySoftware.MyReference...
I don't understand why the Uri has to be absolute when the CloudBlobClient
has a BaseUri
to work from. Do I have to manually prepend the BaseUri
on before I try to get the reference?
There is nothing in the technical reference about this.
Has anyone got relative URIs to work with GetBlobReferenceFromServer
? Is there something that I am fundamentally doing wrong?
Thank you for your feedback. GetBlobReferenceFromServer requires absolute URIs, as it was designed for a specific scenario, where the user just has a URI to the blob and needs to get its blob type to even start working with it.
If you know the type of your blob, I would strongly recommend using GetContainerReference and then GetBlockBlobReference or GetPageBlobReference instead, as these methods do not have to make a call to the Azure Storage Service to get the blob type. Hence, they would reduce cost and increase performance. They also work directly with blob names, not URIs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With