Azure Blob存储帐户返回错误(403)禁止

时间:2019-02-16 07:05:21

标签: c# azure azure-storage-account

在Azure存储帐户上上传excel文件时出现错误, 请提出我该如何解决这个问题。

  

远程服务器返回错误:(403)禁止。在Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync [T]的System.Net.HttpWebRequest.GetResponse()处(RESTCommand`1 cmd,IRetryPolicy策略,OperationContext operationContext)

public long UploadFile( string containerName, string fileName, string mediaType, Stream fileContents )
    {       
        var connectionString = ConfigurationManager.AppSettings["StorageConnectionString"];
        var storageAccount = CloudStorageAccount.Parse( connectionString ); 
        var blobClient = storageAccount.CreateCloudBlobClient();
        var container = blobClient.GetContainerReference( containerName.ToLowerInvariant() );
        if( container.CreateIfNotExists() )
        {
        }

        var blockBlob = container.GetBlockBlobReference( fileName );
        blockBlob.Properties.ContentType = mediaType;

        blockBlob.UploadFromStream( fileContents );

        return blockBlob.Properties.Length;
    }

<add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=myaccountname;AccountKey=Key" />

0 个答案:

没有答案