0

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

远程服务器返回错误:(403) Forbidden。在 System.Net.HttpWebRequest.GetResponse() 在 Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](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" />
4

0 回答 0