CB-12154 file-transfer progressEvent.total = -1 on iOS

Makes chunkedMode=true uploads to contain Content-Length to make progress computable
This commit is contained in:
daserge
2016-11-23 18:57:11 +03:00
parent 655489905a
commit 5a711e8722
2 changed files with 6 additions and 3 deletions
+3 -2
View File
@@ -229,6 +229,8 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
totalPayloadLength += [postBodyBeforeFile length] + [postBodyAfterFile length];
}
[req setValue:[[NSNumber numberWithLongLong:totalPayloadLength] stringValue] forHTTPHeaderField:@"Content-Length"];
if (chunkedMode) {
CFReadStreamRef readStream = NULL;
CFWriteStreamRef writeStream = NULL;
@@ -266,7 +268,6 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
CFRelease(writeStream);
}];
} else {
[req setValue:[[NSNumber numberWithLongLong:totalPayloadLength] stringValue] forHTTPHeaderField:@"Content-Length"];
if (multipartFormUpload) {
[postBodyBeforeFile appendData:fileData];
[postBodyBeforeFile appendData:postBodyAfterFile];
@@ -814,7 +815,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
if (self.direction == CDV_TRANSFER_UPLOAD) {
NSMutableDictionary* uploadProgress = [NSMutableDictionary dictionaryWithCapacity:3];
[uploadProgress setObject:[NSNumber numberWithBool:(!self.chunkedMode)] forKey:@"lengthComputable"];
[uploadProgress setObject:[NSNumber numberWithBool:true] forKey:@"lengthComputable"];
[uploadProgress setObject:[NSNumber numberWithLongLong:totalBytesWritten] forKey:@"loaded"];
[uploadProgress setObject:[NSNumber numberWithLongLong:totalBytesExpectedToWrite] forKey:@"total"];
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:uploadProgress];