Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetBlobReferenceFromServer not working with relative URIs. Error: "Only absolute addresses are permitted"

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?

like image 584
alergy Avatar asked May 23 '14 11:05

alergy


1 Answers

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.

like image 190
Serdar Ozler Avatar answered Nov 07 '22 21:11

Serdar Ozler