From 5f8b889d057ddf3c8c5066fbadabb618d4f3583d Mon Sep 17 00:00:00 2001 From: jdizoglio Date: Wed, 3 May 2017 16:25:15 -0700 Subject: [PATCH] Adding intermediate response handling to BOXAPIMultipartToJSONOperation which supports urlsession tasks transfering data in parts. Allows file requests containing file information the need variable length data support. Our current example is the file information returned via file upload request. --- .../BOXAPIMultipartToJSONOperation.m | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/BoxContentSDK/BoxContentSDK/Operations/BOXAPIMultipartToJSONOperation.m b/BoxContentSDK/BoxContentSDK/Operations/BOXAPIMultipartToJSONOperation.m index 37b940b15..9bafdddd2 100644 --- a/BoxContentSDK/BoxContentSDK/Operations/BOXAPIMultipartToJSONOperation.m +++ b/BoxContentSDK/BoxContentSDK/Operations/BOXAPIMultipartToJSONOperation.m @@ -50,6 +50,17 @@ - (void)abortWithError:(NSError *)error; */ @implementation BOXAPIMultipartToJSONOperation +- (id)initWithURL:(NSURL *)URL HTTPMethod:(NSString *)HTTPMethod body:(NSDictionary *)body queryParams:(NSDictionary *)queryParams session:(BOXAbstractSession *)session +{ + self = [super initWithURL:URL HTTPMethod:HTTPMethod body:body queryParams:queryParams session:session]; + if (self != nil) { + // Initialize the responseData object to mutable data + self.responseData = [NSMutableData data]; + } + + return self; +} + #pragma mark - Append data to upload operation - (void)appendMultipartPieceWithData:(NSData *)data fieldName:(NSString *)fieldName filename:(NSString *)filename MIMEType:(NSString *)MIMEType @@ -127,15 +138,6 @@ - (void)sessionTask:(NSURLSessionTask *)sessionTask } } -- (void)sessionTask:(NSURLSessionTask *)sessionTask processIntermediateData:(NSData *)data -{ - @synchronized (self) { - if (data != nil) { - [self processResponseData:data]; - } - } -} - - (void)sessionTask:(NSURLSessionTask *)sessionTask didFinishWithResponse:(NSURLResponse *)response responseData:(nullable NSData *)responseData error:(NSError *)error { @synchronized (self) {