Open qiu-xm opened 5 years ago
使用2.9.1时: 在获取 image/xxxx_middle 时,报异常: Expected hash not equal to calculated hash
恢复到 2.5.1时正常。。。
相关代码 `
strKey = string.Format("{0}_middle", this.Key);
AliyunOSSDownloadRequest adrRequest = new AliyunOSSDownloadRequest(); adrRequest.LogId = strDownloadAliyunOSSBreviaryImageId; adrRequest.Client = AliyunOSSHandle.DownloadClient; adrRequest.BucketName = AliyunOSSHandle.BucketName; adrRequest.Key = strKey; adrRequest.Path = strBreviaryFile; adrRequest.PartSize = 100 * 1024; AliyunOSSHandle.Download(adrRequest); `
` public static void Download(AliyunOSSDownloadRequest mudrRequest) { OssObject ooObject = mudrRequest.Client.GetObject(mudrRequest.BucketName, mudrRequest.Key); using (Stream requestStream = ooObject.Content) { long lnLength = ooObject.Metadata.ContentLength; long lnPosition = 0L; byte[] buf = new byte[mudrRequest.PartSize]; long lnWatchCount = 0L; System.Diagnostics.Stopwatch swWatch = new System.Diagnostics.Stopwatch(); swWatch.Start(); using (FileStream fs = File.Open(mudrRequest.Path, FileMode.OpenOrCreate)) { var len = 0; while ((len = requestStream.Read(buf, 0, buf.Length)) != 0) { fs.Write(buf, 0, len); if (mudrRequest.ProgressChanged) { lnPosition += len; lnWatchCount += len;
AliyunOSSDownloadProgressChanged adpcChanged = new AliyunOSSDownloadProgressChanged(); adpcChanged.Progress = 100.0D * lnPosition / lnLength; adpcChanged.PartIndexs = new SafeList<int>(); long lnTime = swWatch.ElapsedMilliseconds; if (lnTime >= 500) { swWatch.Reset(); swWatch.Start(); adpcChanged.SpeekValid = true; adpcChanged.Speek = lnWatchCount / lnTime * 1000; if (adpcChanged.Speek > 0) { adpcChanged.RemainingTime = (lnLength - lnPosition) / adpcChanged.Speek; } lnWatchCount = 0L; } mudrRequest.OnDownloadProgressChanged(adpcChanged); } } swWatch.Stop(); } } if (!string.IsNullOrEmpty(mudrRequest.MD5)) { // MD5比较 } if (mudrRequest.ProgressChanged) { AliyunOSSDownloadProgressChanged mudcEndChanged = new AliyunOSSDownloadProgressChanged(); mudcEndChanged.Progress = 100.0D; mudcEndChanged.PartIndexs = new SafeList<int>(); mudrRequest.OnDownloadProgressChanged(mudcEndChanged); }
} `
`
public class AliyunOSSDownloadRequest { private string mLogId; public string LogId { get { return mLogId; } set { mLogId = value; } } private OssClient mClient; public OssClient Client { get { return mClient; } set { mClient = value; } } private string mBucketName; public string BucketName { get { return mBucketName; } set { mBucketName = value; } } private string mKey; public string Key { get { return mKey; } set { mKey = value; } } private string mMD5; public string MD5 { get { return mMD5; } set { mMD5 = value; } } private string mPath; public string Path { get { return mPath; } set { mPath = value; } } private long mLength; public long Length { get { return mLength; } set { mLength = value; } } private long mPartSize; public long PartSize { get { return mPartSize; } set { mPartSize = value; } } private SafeList<int> mPartIndexs = new SafeList<int>(); public SafeList<int> PartIndexs { get { return mPartIndexs; } set { mPartIndexs = value; } } private SafeQueue<AliyunOSSDownloadPartStream> mPartStream = new SafeQueue<AliyunOSSDownloadPartStream>(); public SafeQueue<AliyunOSSDownloadPartStream> PartStream { get { return mPartStream; } set { mPartStream = value; } } public event EventHandler<AliyunOSSDownloadProgressChanged> DownloadProgressChanged; public bool ProgressChanged { get { return this.DownloadProgressChanged != null; } } public void OnDownloadProgressChanged(AliyunOSSDownloadProgressChanged e) { if (this.DownloadProgressChanged != null) { this.DownloadProgressChanged(this, e); } } }
Aliyun.OSS.Common.ClientException: Expected hash not equal to calculated hash 在 Aliyun.OSS.Common.Internal.HashStream.CalculateHash() 在 Aliyun.OSS.Common.Internal.HashStream.Close() 在 System.IO.Stream.Dispose()
使用2.9.1时: 在获取 image/xxxx_middle 时,报异常: Expected hash not equal to calculated hash
恢复到 2.5.1时正常。。。
相关代码 `
strKey = string.Format("{0}_middle", this.Key);
AliyunOSSDownloadRequest adrRequest = new AliyunOSSDownloadRequest(); adrRequest.LogId = strDownloadAliyunOSSBreviaryImageId; adrRequest.Client = AliyunOSSHandle.DownloadClient; adrRequest.BucketName = AliyunOSSHandle.BucketName; adrRequest.Key = strKey; adrRequest.Path = strBreviaryFile; adrRequest.PartSize = 100 * 1024; AliyunOSSHandle.Download(adrRequest); `
` public static void Download(AliyunOSSDownloadRequest mudrRequest) { OssObject ooObject = mudrRequest.Client.GetObject(mudrRequest.BucketName, mudrRequest.Key); using (Stream requestStream = ooObject.Content) { long lnLength = ooObject.Metadata.ContentLength; long lnPosition = 0L; byte[] buf = new byte[mudrRequest.PartSize]; long lnWatchCount = 0L; System.Diagnostics.Stopwatch swWatch = new System.Diagnostics.Stopwatch(); swWatch.Start(); using (FileStream fs = File.Open(mudrRequest.Path, FileMode.OpenOrCreate)) { var len = 0; while ((len = requestStream.Read(buf, 0, buf.Length)) != 0) { fs.Write(buf, 0, len); if (mudrRequest.ProgressChanged) { lnPosition += len; lnWatchCount += len;
} `
`
`