1414#import " QNHttpManager.h"
1515#import " QNUploadOption+Private.h"
1616#import " QNRecorderDelegate.h"
17+ #import " QNCrc32.h"
1718
1819typedef void (^task)(void );
1920
@@ -34,6 +35,7 @@ @interface QNResumeUpload ()
3435@property UInt64 modifyTime;
3536@property (nonatomic , weak ) id <QNRecorderDelegate> recorder;
3637
38+ @property UInt32 chunkCrc;
3739
3840- (void )makeBlock : (NSString *)uphost
3941 offset : (UInt32)offset
@@ -216,8 +218,15 @@ - (void)nextTask:(UInt32)offset retriedTimes:(int)retried host:(NSString *)host
216218 [self nextTask: offset retriedTimes: retried + 1 host: nextHost];
217219 return ;
218220 }
221+
222+ if (resp == nil ) {
223+ [self nextTask: offset retriedTimes: retried host: host];
224+ return ;
225+ }
226+
219227 NSString *ctx = resp[@" ctx" ];
220- if (ctx == nil ) {
228+ NSNumber *crc = resp[@" crc32" ];
229+ if (ctx == nil || crc == nil || [crc unsignedLongValue ] != _chunkCrc) {
221230 [self nextTask: offset retriedTimes: retried host: host];
222231 return ;
223232 }
@@ -252,6 +261,7 @@ - (void)makeBlock:(NSString *)uphost
252261 complete : (QNCompleteBlock)complete {
253262 NSData *data = [self .data subdataWithRange: NSMakeRange (offset, (unsigned int )chunkSize)];
254263 NSString *url = [[NSString alloc ] initWithFormat: @" http://%@ /mkblk/%u " , uphost, (unsigned int )blockSize];
264+ _chunkCrc = [QNCrc32 data: data];
255265 [self post: url withData: data withCompleteBlock: complete withProgressBlock: progressBlock];
256266}
257267
@@ -264,7 +274,7 @@ - (void)putChunk:(NSString *)uphost
264274 NSData *data = [self .data subdataWithRange: NSMakeRange (offset, (unsigned int )size)];
265275 UInt32 chunkOffset = offset % kQNBlockSize ;
266276 NSString *url = [[NSString alloc ] initWithFormat: @" http://%@ /bput/%@ /%u " , uphost, context, (unsigned int )chunkOffset];
267-
277+ _chunkCrc = [QNCrc32 data: data];
268278 [self post: url withData: data withCompleteBlock: complete withProgressBlock: progressBlock];
269279}
270280
0 commit comments