Question

I get an exception when using the method DeleteIfExists from the CloudBlockBlob class.

This is my code:

CloudBlobClient blobClient = this._storageAccount.CreateCloudBlobClient();

            directory = directory.ToLower();

            string containerDirectory = this.GetContainer(directory);
            string relativePathWithoutContainer = this.GetRelativePathWithoutContainer(directory);

            CloudBlobContainer container = blobClient.GetContainerReference(containerDirectory);
            container.CreateIfNotExist();
            container.SetPermissions(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob });

            foreach (HttpPostedFileBase file in files)
            {
                CloudBlockBlob blob = container.GetBlockBlobReference(string.Format("{0}/{1}", relativePathWithoutContainer, file.FileName.ToLower()));
                blob.DeleteIfExists();
                blob.UploadFromStream(file.InputStream,new BlobRequestOptions());
            }

            return true;

I get the exception at the line:

blob.DeleteIfExists();

The details of the exception are:

Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.

Was it helpful?

Solution

Got an example from here try to add these and see if it works

// Delete the blob if it already exists, also deleting any snapshots.

BlobRequestOptions options = new BlobRequestOptions();

options.DeleteSnapshotsOption = DeleteSnapshotsOption.IncludeSnapshots;

blob.DeleteIfExists(options);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top