2
votes

I am using Azure Storage to store some files on Azure platform, using using the new version 4.X of WindowsAzure.Storage Nuget package to interact with the storage.

I use a full uri with SAS key to connect to my container:

var uri = new Uri("https://mystorage.blob.core.windows.net/mycontainer?sr=c&si=all-rights&sig=mykey");
var container = new CloudBlobContainer(uri);

The policy "all-rights" is configured in Azure Storage and provides me with all rights on the container.

The upload of the file works well

var myBlob = container.GetBlockBlobReference("desert.jpg");
myBlob.UploadFromFile(@"path\to\desert.jpg", FileMode.OpenOrCreate);

When I try to check for blob existence:

var blob = container.GetBlockBlobReference("desert.jpg");
var exists = blob.Exists();

It works like a charm when the blob named "desert.jpg" does not exists, but I get an exception when the blob does exists:

Microsoft.WindowsAzure.Storage.StorageException: Blob type of the blob reference doesn't match blob type of the blob. ---> System.InvalidOperationException: Blob type of the blob reference doesn't match blob type of the blob. at Microsoft.WindowsAzure.Storage.Blob.CloudBlobSharedImpl.UpdateAfterFetchAttributes(BlobAttributes attributes, HttpWebResponse response, Boolean ignoreMD5) at Microsoft.WindowsAzure.Storage.Blob.CloudBlobSharedImpl.<>c__DisplayClasse.b__d(RESTCommand1 cmd, HttpWebResponse resp, Exception ex, OperationContext ctx) at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand1 cmd, IRetryPolicy policy, OperationContext operationContext) --- End of inner exception stack trace --- at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.Exists(Boolean primaryOnly, BlobRequestOptions options, OperationContext operationContext) at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.Exists(BlobRequestOptions options, OperationContext operationContext) at AzureStorage.Program.Main() in c:\Users\RMagny\Documents\Visual Studio 2012\Projects\AzureStorage\AzureStorage\Program.cs:line 16 Request Information RequestID:8ab1351a-1c66-4193-ad54-bbcaf2a20132 RequestDate:Thu, 31 Jul 2014 13:54:20 GMT StatusMessage:OK

Is it the right way to check for blob existence with the latest version of the library?

I wrote this kind of code when I was on the previous 3.2.1 version of the Nuget package, and it worked just fine.

I don't know if I'm facing a bug in the library, or if there are new paradigms to use for this.

By the way, it seems I have the same issues with all methods to get/set the properties of the blob (methods SetProperties() and FetchProperties())

1

1 Answers

3
votes

The issue is caused by how your SAS token was generated. It does not contain the sv parameter, which causes the request to be processed using a very old Azure Storage Services version. And every version of Azure Storage Client Library is tied to a specific version of Azure Storage Services, which leads to the issue you are experiencing. For more information on versioning, please refer to Versioning for the Azure Storage Services.

I would recommend upgrading to a newer SAS token version by either generating it using Azure Storage Client Library or using a newer version of your favorite explorer application.