The remote server returned an error: (403) Server failed to authenticate the request in Xamarin PCL

Viewed 278

I am trying to list all my blobs from Azure storage container. I am using Xamarin.Forms PCL, debugging on an Android emulator. I receive the following error: The remote server returned an error: (403) Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.. I tried to put my code in a console app and it works without any error.

For the Microsoft.WindowsAzure.Storage to work on PCL I had to install WindowsAzure.Storage-Preview.3.2.0-preview, adding the reference manually on my References list.

Here is my code:

CloudStorageAccount account = CloudStorageAccount.Parse(StorageConnectionString);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference(containerName.ToLower());
var blobs = await MediaService.GetBlobsListAsync(container);


public static async Task<IList<CloudBlockBlob>> GetBlobsListAsync(CloudBlobContainer container)
        {
            try
            {
                var allBlobsList = new List<CloudBlockBlob>();
                BlobContinuationToken token = null;

                do
                {
                    var result = await container.ListBlobsSegmentedAsync(token);
                    if (result.Results.Count() > 0)
                    {
                        var blobs = result.Results.Select(item => item as CloudBlockBlob);
                        allBlobsList.AddRange(blobs.ToList());
                    }
                    token = result.ContinuationToken;
                } while (token != null);

                return allBlobsList;
            }
            catch (StorageException ex)
            {
                throw new StorageException($"Additional error information:{ex.ToString()}", ex.InnerException);
            }
        }

The error appears just when I try to call container.ListBlobsSegmentedAsync(token);

0 Answers
Related