mirror of
https://github.com/apache/cordova-plugin-file-transfer.git
synced 2026-06-05 00:00:35 +08:00
Merge dev branch @ 'r0.4.3' into master for release
This commit is contained in:
@@ -68,3 +68,16 @@
|
||||
* CB-6000 Android: Nginx rejects Content-Type without a space before "boundary".
|
||||
* CB-4907 Android: Close stream when we're finished with it
|
||||
* CB-6022 Add backwards-compatibility notes to doc
|
||||
|
||||
### 0.4.3 (Apr 17, 2014)
|
||||
* CB-6422 [windows8] use cordova/exec/proxy
|
||||
* iOS: Fix error where files were not removed on abort
|
||||
* CB-5175: [ios] CDVFileTransfer asynchronous download (Fixes #24)
|
||||
* [ios] Cast id references to NSURL to avoid compiler warnings (Fixes: apache/cordova-plugin-file-transfer#18)
|
||||
* CB-6212: [iOS] fix warnings compiled under arm64 64-bit
|
||||
* CB-5762: [FireOS] android: Fix lengthComputable set wrong for gzip downloads
|
||||
* CB-5631: [FireOS] Removed SimpleTrackingInputStream.read(byte[] buffer)
|
||||
* CB-4907: [FireOS] Close stream when we're finished with it
|
||||
* CB-6000: [FireOS] Nginx rejects Content-Type without a space before "boundary".
|
||||
* CB-6050: [FireOS] Use instance method on actual file plugin object to get FileEntry to return on download
|
||||
* CB-6460: Update license headers
|
||||
|
||||
+20
-1
@@ -1,8 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
id="org.apache.cordova.file-transfer"
|
||||
version="0.4.2">
|
||||
version="0.4.3">
|
||||
<name>File Transfer</name>
|
||||
<description>Cordova File Transfer Plugin</description>
|
||||
<license>Apache 2.0</license>
|
||||
|
||||
@@ -84,4 +84,4 @@ extern NSString* const kOptionsKeyCookie;
|
||||
@property (nonatomic, strong) CDVFileTransferEntityLengthRequest* entityLengthRequest;
|
||||
@property (nonatomic, strong) CDVFile *filePlugin;
|
||||
|
||||
@end;
|
||||
@end
|
||||
|
||||
+33
-23
@@ -58,7 +58,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
||||
bytesToWrite - totalBytesWritten);
|
||||
if (result < 0) {
|
||||
CFStreamError error = CFWriteStreamGetError(stream);
|
||||
NSLog(@"WriteStreamError domain: %ld error: %ld", error.domain, error.error);
|
||||
NSLog(@"WriteStreamError domain: %ld error: %ld", error.domain, (long)error.error);
|
||||
return result;
|
||||
} else if (result == 0) {
|
||||
return result;
|
||||
@@ -207,7 +207,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
||||
if (mimeType != nil) {
|
||||
[postBodyBeforeFile appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n", mimeType] dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
}
|
||||
[postBodyBeforeFile appendData:[[NSString stringWithFormat:@"Content-Length: %d\r\n\r\n", [fileData length]] dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
[postBodyBeforeFile appendData:[[NSString stringWithFormat:@"Content-Length: %ld\r\n\r\n", (long)[fileData length]] dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
|
||||
DLog(@"fileData length: %d", [fileData length]);
|
||||
NSData* postBodyAfterFile = [[NSString stringWithFormat:@"\r\n--%@--\r\n", kFormBoundary] dataUsingEncoding:NSUTF8StringEncoding];
|
||||
@@ -293,7 +293,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
||||
return;
|
||||
} else {
|
||||
// Extract the path part out of a file: URL.
|
||||
NSString* filePath = [source hasPrefix:@"/"] ? [source copy] : [[NSURL URLWithString:source] path];
|
||||
NSString* filePath = [source hasPrefix:@"/"] ? [source copy] : [(NSURL *)[NSURL URLWithString:source] path];
|
||||
if (filePath == nil) {
|
||||
// We couldn't find the asset. Send the appropriate error.
|
||||
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[self createFileTransferError:NOT_FOUND_ERR AndSource:source AndTarget:server]];
|
||||
@@ -430,8 +430,12 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
||||
@synchronized (activeTransfers) {
|
||||
activeTransfers[delegate.objectId] = delegate;
|
||||
}
|
||||
|
||||
[delegate.connection start];
|
||||
// Downloads can take time
|
||||
// sending this to a new thread calling the download_async method
|
||||
dispatch_async(
|
||||
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL),
|
||||
^(void) { [delegate.connection start];}
|
||||
);
|
||||
}
|
||||
|
||||
- (NSMutableDictionary*)createFileTransferError:(int)code AndSource:(NSString*)source AndTarget:(NSString*)target
|
||||
@@ -492,9 +496,9 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
||||
|
||||
- (CDVFileTransferEntityLengthRequest*)initWithOriginalRequest:(NSURLRequest*)originalRequest andDelegate:(CDVFileTransferDelegate*)originalDelegate;
|
||||
|
||||
@end;
|
||||
@end
|
||||
|
||||
@implementation CDVFileTransferEntityLengthRequest;
|
||||
@implementation CDVFileTransferEntityLengthRequest
|
||||
|
||||
- (CDVFileTransferEntityLengthRequest*)initWithOriginalRequest:(NSURLRequest*)originalRequest andDelegate:(CDVFileTransferDelegate*)originalDelegate
|
||||
{
|
||||
@@ -583,7 +587,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
||||
{
|
||||
NSFileManager* fileMgr = [NSFileManager defaultManager];
|
||||
|
||||
[fileMgr removeItemAtPath:self.target error:nil];
|
||||
[fileMgr removeItemAtPath:[self targetFilePath] error:nil];
|
||||
}
|
||||
|
||||
- (void)cancelTransfer:(NSURLConnection*)connection
|
||||
@@ -608,6 +612,21 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
||||
[self.command.commandDelegate sendPluginResult:result callbackId:callbackId];
|
||||
}
|
||||
|
||||
- (NSString *)targetFilePath
|
||||
{
|
||||
NSString *path = nil;
|
||||
CDVFilesystemURL *sourceURL = [CDVFilesystemURL fileSystemURLWithString:self.target];
|
||||
if (sourceURL && sourceURL.fileSystemName != nil) {
|
||||
// This requires talking to the current CDVFile plugin
|
||||
NSObject<CDVFileSystem> *fs = [self.filePlugin filesystemForURL:sourceURL];
|
||||
path = [fs filesystemPathForURL:sourceURL];
|
||||
} else {
|
||||
// Extract the path part out of a file: URL.
|
||||
path = [self.target hasPrefix:@"/"] ? [self.target copy] : [(NSURL *)[NSURL URLWithString:self.target] path];
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response
|
||||
{
|
||||
NSError* __autoreleasing error = nil;
|
||||
@@ -638,20 +657,11 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
||||
}
|
||||
if ((self.direction == CDV_TRANSFER_DOWNLOAD) && (self.responseCode >= 200) && (self.responseCode < 300)) {
|
||||
// Download response is okay; begin streaming output to file
|
||||
NSString *filePath = nil;
|
||||
CDVFilesystemURL *sourceURL = [CDVFilesystemURL fileSystemURLWithString:self.target];
|
||||
if (sourceURL && sourceURL.fileSystemName != nil) {
|
||||
// This requires talking to the current CDVFile plugin
|
||||
NSObject<CDVFileSystem> *fs = [self.filePlugin filesystemForURL:sourceURL];
|
||||
filePath = [fs filesystemPathForURL:sourceURL];
|
||||
} else {
|
||||
// Extract the path part out of a file: URL.
|
||||
NSString* filePath = [self.target hasPrefix:@"/"] ? [self.target copy] : [[NSURL URLWithString:self.target] path];
|
||||
if (filePath == nil) {
|
||||
// We couldn't find the asset. Send the appropriate error.
|
||||
[self cancelTransferWithError:connection errorMessage:[NSString stringWithFormat:@"Could not create target file"]];
|
||||
return;
|
||||
}
|
||||
NSString *filePath = [self targetFilePath];
|
||||
if (filePath == nil) {
|
||||
// We couldn't find the asset. Send the appropriate error.
|
||||
[self cancelTransferWithError:connection errorMessage:[NSString stringWithFormat:@"Could not create target file"]];
|
||||
return;
|
||||
}
|
||||
|
||||
NSString* parentPath = [filePath stringByDeletingLastPathComponent];
|
||||
@@ -765,4 +775,4 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
||||
return self;
|
||||
}
|
||||
|
||||
@end;
|
||||
@end
|
||||
|
||||
@@ -117,4 +117,4 @@ module.exports = {
|
||||
}
|
||||
};
|
||||
|
||||
require("cordova/windows8/commandProxy").add("FileTransfer",module.exports);
|
||||
require("cordova/exec/proxy").add("FileTransfer",module.exports);
|
||||
|
||||
Reference in New Issue
Block a user