1

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.

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.