Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 400上载到Azure Blob存储时出错_C#_Azure - Fatal编程技术网

C# 400上载到Azure Blob存储时出错

C# 400上载到Azure Blob存储时出错,c#,azure,C#,Azure,我的应用程序是用C#构建的,一直使用Azure Blob存储的标准gen 2版本将文件上载到容器,但我们在成功上载文件方面的行为不一致,因此我们决定尝试降低延迟的高级版本 从文档来看,似乎没有任何关于代码方面的方法应该有所不同的建议。然而,我们收到了400个错误的请求,试图上传。我们尝试使用Sas,但仍然遇到同样的挑战。我还尝试手动创建容器,而不是从代码动态创建容器,但仍然遇到相同的问题 这里是这两种方法的片段,希望有人能给我指出正确的方向 与sas //

我的应用程序是用C#构建的,一直使用Azure Blob存储的标准gen 2版本将文件上载到容器,但我们在成功上载文件方面的行为不一致,因此我们决定尝试降低延迟的高级版本

从文档来看,似乎没有任何关于代码方面的方法应该有所不同的建议。然而,我们收到了400个错误的请求,试图上传。我们尝试使用Sas,但仍然遇到同样的挑战。我还尝试手动创建容器,而不是从代码动态创建容器,但仍然遇到相同的问题

这里是这两种方法的片段,希望有人能给我指出正确的方向

与sas

                    // level APIs
                    AccountSasBuilder sas = new AccountSasBuilder
                    {
                        // Allow access to blobs
                        Services = AccountSasServices.Blobs,

                        // Allow access to the service level APIs
                        ResourceTypes = AccountSasResourceTypes.Service,

                        // Access expires in 1 hour!
                        ExpiresOn = DateTimeOffset.UtcNow.AddHours(1)
                    };
                    // Allow read access
                    sas.SetPermissions(AccountSasPermissions.All);

                    // Create a SharedKeyCredential that we can use to sign the SAS token
                    StorageSharedKeyCredential credential = new StorageSharedKeyCredential(StorageName,StorageKey);

                    // Build a SAS URI
                    UriBuilder sasUri = new UriBuilder(StorageURL);
                    sasUri.Query = sas.ToSasQueryParameters(credential).ToString();

                    // Create a client that can authenticate with the SAS URI
                    BlobServiceClient service = new BlobServiceClient(sasUri.Uri);

                    //var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureWebJobsStorage"]);
                    //var client = storageAccount.CreateCloudBlobClient();

                    var blobContainer = service.GetBlobContainerClient(container);
                    //blobContainer.CreateIfNotExists(PublicAccessType.BlobContainer);
                    var blockBlob = blobContainer.GetBlobClient(file.Substring(file.LastIndexOf('/') + 1));
                    using (var fileStream = WaitForFile(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        var response = blockBlob.UploadAsync(fileStream).Result;
                        fileStream.Close();
                    }
没有sas

        var client = storageAccount.CreateCloudBlobClient();

        var blobContainer = client.GetContainerReference(container);
        blobContainer.CreateIfNotExists(BlobContainerPublicAccessType.Blob);
                    var blockBlob = blobContainer.GetBlockBlobReference(file.Substring(file.LastIndexOf('/') + 1));
                    using (var fileStream = WaitForFile(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        blockBlob.UploadFromStream(fileStream);
                        fileStream.Close();
                    } ```

在不知道例外情况的情况下,我认为您可能会出现以下情况:

Premium GPv2帐户不支持块Blob或文件、表和队列服务

您可能希望尝试使用
高级BlockBlocksStorage

但是,premium BlockBlob存储帐户确实支持block和append Blob


如果没有,请尝试捕获异常。自定义异常在
RequestInformation
属性中包含
HttpStatusMessage
,您可以在其中找到错误的请求案例。

错误代码对应于

BlockListToolLong错误请求(400)阻止列表不能包含更多 超过50000个街区

此处列出了其他错误代码:


您需要通过减少上传的块blob大小来修复错误。

请详细查看错误消息并使用filddler捕获请求,好吗?