2

I'm using azure storage client to upload some files to Azure blob storage. This upload is happening from a dll file stored in local machine. following is the code i'm using.

  public bool UploadBlob(byte[] fileContent, CloudStorageAccount account, string containerName, string blobName)
    {
        try
        {
            CloudBlobClient blobclient = account.CreateCloudBlobClient();
            CloudBlobContainer container = blobclient.GetContainerReference(containerName);
            container.CreateIfNotExist();
            CloudBlockBlob blob = container.GetBlockBlobReference(blobName);

            HashSet<string> blocklist = new HashSet<string>();
            foreach (FileBlock block in GetFileBlocks(fileContent))
            {

                if (ScanTool.mIsThreadStop)
                    return false;
                ScanTool.mDocumentUploadedSize += block.Content.Length;
                blob.PutBlock(
                    block.Id,
                    new MemoryStream(block.Content, true),
                    null
                    );
                blocklist.Add(block.Id);
            }
            blob.PutBlockList(blocklist);
            blob.FetchAttributes();
            return blob.Properties.Length == fileContent.Length;
        }
        catch (Exception e) {
            Log.WriteErrorLog(e, "UploadBlob at AzureBlobUtilCS");
            throw new System.Net.WebException();
        }
    }

I'm calling above upload method as follows and it throws "Proxy Authentication failed" Exception on following code

    try
        {
            CloudBlobContainer container = AzureHelper.GetContainer(containerName, accountName, accountKey);
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(AzureHelper.GetConnectionString(accountName, accountKey));
            return UploadBlob(fileContent, storageAccount, containerName, blobName);
        }catch(Exception e)
        {
            WriteInformationMessage("exception at UploadBlob11 =" + e.Message);
            return false;
        }

This issue is encounter in one of my client site and he is saying they have a proxy in their local network. Proxy name is bluecoat proxy SG 900

How to get rid of this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Dehan Wjiesekara
  • 3,152
  • 3
  • 32
  • 46
  • You can try setting the proxy settings in app/web config file: https://msdn.microsoft.com/en-us/library/kd3cf2ex(v=vs.110).aspx. – Gaurav Mantri May 31 '16 at 11:46
  • Please follow Gaurav's instruction above. :) – Zhaoxing Lu Jun 01 '16 at 02:06
  • @Zhaoxing Lu is there any way for authenticate proxy using azure storage client library – Dehan Wjiesekara Jun 01 '16 at 12:23
  • I don't think the setting is in Azure Storage Client Library level. You should set it globally in defaultProxy, related questions: http://stackoverflow.com/questions/299940/how-should-i-set-the-default-proxy-to-use-default-credentials , http://stackoverflow.com/questions/12050415/set-default-proxy-programmatically-instead-of-using-app-config – Zhaoxing Lu Jun 01 '16 at 14:01

1 Answers1

1

I was experiencing similar issues, not only in Azure Storage, but also on the entire website.

In order to disable the default proxy used by Azure Storage, which happens to be the default proxy used by the HttpClient class, I changed Web.config, by adding the defaultProxy element:

<configuration>
  <system.net>
    <defaultProxy enabled="false"></defaultProxy>
  </system.net>
</configuration>

If you must configure the default proxy, instead of disabling it, you can also do so within that same element, according to the docs: https://msdn.microsoft.com/en-us/library/kd3cf2ex(v=vs.110).aspx

carlosrafaelgn
  • 831
  • 1
  • 16
  • 19