通过C#和MD5检查中的PutBlockList方法上传到blob

通过C#和MD5检查中的PutBlockList方法上传到blob,c#,azure,upload,C#,Azure,Upload,我正在尝试使用PutBlockList方法将电影块上传到C#中的Azure blob。我一直在编写一个测试代码,问题是,当我使用MD5来保证数据的完整性时,我故意破坏数据,导致不同的MD5值,服务器不会拒绝上传并接受它,而在正确的代码中,它必须被拒绝 var upload = Take.CommitBlocks(shot,takeId,data); .... blob.Properties.ContentMD5 = md5; return Task.Factory.FromAsync(b

我正在尝试使用PutBlockList方法将电影块上传到C#中的Azure blob。我一直在编写一个测试代码,问题是,当我使用MD5来保证数据的完整性时,我故意破坏数据,导致不同的MD5值,服务器不会拒绝上传并接受它,而在正确的代码中,它必须被拒绝

 var upload = Take.CommitBlocks(shot,takeId,data);
 ....
 blob.Properties.ContentMD5 = md5;
 return Task.Factory.FromAsync(blob.BeginPutBlockList(ids,null,null),blob.EndPutBlockList);

在我的测试方法中,我故意破坏数据,但系统仍然接受数据。我怎样才能解决这个问题?在正确的代码中,我应该收到错误400,但我什么也没有得到

见。Put Block List不会验证MD5,但每次Put Block调用都会单独验证MD5。

我参加聚会晚了几年,但从我所看到的情况来看,此功能仍然没有内置到API和SDK中(Assembly Microsoft.WindowsAzure.Storage,Version=8.1.4.0)。也就是说,以下是我的工作:

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.IO;
using System.Threading.Tasks;

/// <summary>
/// Extension methods for <see cref="CloudBlockBlob"/>
/// </summary>
public static class CloudBlockBlobExtensions
{
    /// <summary>
    /// Attempts to open a stream to download a range, and if it fails with <see cref="StorageException"/> 
    /// then the message is compared to a string representation of the expected message if the MD5
    /// property does not match the property sent.
    /// </summary>
    /// <param name="instance">The instance of <see cref="CloudBlockBlob"/></param>
    /// <returns>Returns a false if the calculated MD5 does not match the existing property.</returns>
    /// <exception cref="ArgumentNullException">If <paramref name="instance"/> is null.</exception>
    /// <remarks>This is a hack, and if the message from storage API changes, then this will fail.</remarks>
    public static async Task<bool> IsValidContentMD5(this CloudBlockBlob instance)
    {
        if (instance == null)
            throw new ArgumentNullException(nameof(instance));

        try
        {
            using (var ms = new MemoryStream())
            {
                await instance.DownloadRangeToStreamAsync(ms, null, null);
            }
        }
        catch (StorageException ex)
        {
            return !ex.Message.Equals("Calculated MD5 does not match existing property", StringComparison.Ordinal);
        }

        return true;
    }
} 
使用Microsoft.WindowsAzure.Storage;
使用Microsoft.WindowsAzure.Storage.Blob;
使用制度;
使用System.IO;
使用System.Threading.Tasks;
/// 
///可拓方法
/// 
公共静态类CloudBlockBlobeExtensions
{
/// 
///尝试打开流以下载范围,如果失败
///然后,如果MD5
///属性与发送的属性不匹配。
/// 
///实例
///如果计算的MD5与现有属性不匹配,则返回false。
///If为空。
///这是一种黑客行为,如果来自存储API的消息发生更改,则此操作将失败。
公共静态异步任务IsValidContentMD5(此CloudBlockBlob实例)
{
if(实例==null)
抛出新ArgumentNullException(nameof(instance));
尝试
{
使用(var ms=new MemoryStream())
{
wait instance.DownloadRangeToStreamAsync(ms,null,null);
}
}
捕获(StorageException-ex)
{
return!ex.Message.Equals(“计算的MD5与现有属性不匹配”,StringComparison.Ordinal);
}
返回true;
}
} 
~z~干杯