diff --git a/src/ios/CDVFileTransfer.m b/src/ios/CDVFileTransfer.m index 6024901..9b01049 100644 --- a/src/ios/CDVFileTransfer.m +++ b/src/ios/CDVFileTransfer.m @@ -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]; diff --git a/tests/tests.js b/tests/tests.js index 7149091..e303b45 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -1506,7 +1506,9 @@ exports.defineAutoTests = function () { obj = JSON.parse(uploadResult.response); if (specContext.uploadOptions.chunkedMode) { - expect(obj["content-length"]).not.toBeDefined("Expected Content-Length not to be defined"); + if (!isIos) { + expect(obj["content-length"]).not.toBeDefined("Expected Content-Length not to be defined"); + } expect(obj["transfer-encoding"].toLowerCase()).toEqual("chunked"); } else { expect(obj["content-length"]).toBeDefined("Expected Content-Length to be defined");