mirror of
https://github.com/apache/cordova-plugin-file-transfer.git
synced 2026-04-28 00:02:49 +08:00
CB-10974 Cordova file transfer Content-Length header problem
Fixed iOS logic to not to include Content-Length when chunkedMode=true Fixed Android logic preventing chunkedMode to be enabled for http uploads Added tests for chunkedMode Documented chunkedMode not supported on Windows Documented Uploading of an empty file is not supported for chunkedMode=true and multipart=false for iOS, pended the corresponding test
This commit is contained in:
@@ -229,8 +229,6 @@ 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;
|
||||
@@ -255,7 +253,11 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
WriteDataToStream(fileData, writeStream);
|
||||
if (totalPayloadLength > 0) {
|
||||
WriteDataToStream(fileData, writeStream);
|
||||
} else {
|
||||
NSLog(@"Uploading of an empty file is not supported for chunkedMode=true and multipart=false");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NSLog(@"FileTransfer: Failed to open writeStream");
|
||||
@@ -264,6 +266,7 @@ 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];
|
||||
@@ -281,6 +284,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
||||
NSString* server = [command argumentAtIndex:1];
|
||||
BOOL trustAllHosts = [[command argumentAtIndex:6 withDefault:[NSNumber numberWithBool:NO]] boolValue]; // allow self-signed certs
|
||||
NSString* objectId = [command argumentAtIndex:9];
|
||||
BOOL chunkedMode = [[command argumentAtIndex:7 withDefault:[NSNumber numberWithBool:YES]] boolValue];
|
||||
|
||||
CDVFileTransferDelegate* delegate = [[CDVFileTransferDelegate alloc] init];
|
||||
|
||||
@@ -292,6 +296,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
||||
delegate.target = server;
|
||||
delegate.trustAllHosts = trustAllHosts;
|
||||
delegate.filePlugin = [self.commandDelegate getCommandInstance:@"File"];
|
||||
delegate.chunkedMode = chunkedMode;
|
||||
|
||||
return delegate;
|
||||
}
|
||||
@@ -809,7 +814,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
||||
if (self.direction == CDV_TRANSFER_UPLOAD) {
|
||||
NSMutableDictionary* uploadProgress = [NSMutableDictionary dictionaryWithCapacity:3];
|
||||
|
||||
[uploadProgress setObject:[NSNumber numberWithBool:true] forKey:@"lengthComputable"];
|
||||
[uploadProgress setObject:[NSNumber numberWithBool:(!self.chunkedMode)] forKey:@"lengthComputable"];
|
||||
[uploadProgress setObject:[NSNumber numberWithLongLong:totalBytesWritten] forKey:@"loaded"];
|
||||
[uploadProgress setObject:[NSNumber numberWithLongLong:totalBytesExpectedToWrite] forKey:@"total"];
|
||||
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:uploadProgress];
|
||||
|
||||
Reference in New Issue
Block a user