From f115394912e08800d20ff6ca315b30e39562460d Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Thu, 27 Feb 2014 12:29:15 -0500 Subject: [PATCH 01/10] CB-6114 Incremented plugin version on dev branch. --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 30e9588..842081a 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="0.4.3-dev"> File Transfer Cordova File Transfer Plugin Apache 2.0 From c35ca1a5c22298542f84e372a3f9ff6da914a05b Mon Sep 17 00:00:00 2001 From: Archana Naik Date: Mon, 10 Mar 2014 23:02:28 -0700 Subject: [PATCH 02/10] Upleveled from android port with following commits: 3c1ff16 Andrew Grieve - CB-5762 android: Fix lengthComputable set wrong for gzip downloads 8374b3d Colin Mahoney - CB-5631 Removed SimpleTrackingInputStream.read(byte[] buffer) 6f91ac3 Bas Bosman - CB-4907 Close stream when we're finished with it 651460f Christoph Neumann - CB-6000 Nginx rejects Content-Type without a space before "boundary". 35f80e4 Ian Clelland - CB-6050: Use instance method on actual file plugin object to get FileEntry to return on download --- src/amazon/FileTransfer.java | 53 +++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/src/amazon/FileTransfer.java b/src/amazon/FileTransfer.java index 2e0c31c..513400e 100644 --- a/src/amazon/FileTransfer.java +++ b/src/amazon/FileTransfer.java @@ -158,11 +158,8 @@ public class FileTransfer extends CordovaPlugin { return updateBytesRead(super.read()); } - @Override - public int read(byte[] buffer) throws IOException { - return updateBytesRead(super.read(buffer)); - } - + // Note: FilterInputStream delegates read(byte[] bytes) to the below method, + // so we don't override it or else double count (CB-5631). @Override public int read(byte[] bytes, int offset, int count) throws IOException { return updateBytesRead(super.read(bytes, offset, count)); @@ -318,7 +315,7 @@ public class FileTransfer extends CordovaPlugin { // Use a post method. conn.setRequestMethod(httpMethod); - conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + BOUNDARY); + conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY); // Set the cookies on the response String cookie = AmazonCookieManager.getInstance().getCookie(target); @@ -585,15 +582,19 @@ public class FileTransfer extends CordovaPlugin { if(err != null) { BufferedReader reader = new BufferedReader(new InputStreamReader(err, "UTF-8")); - String line = reader.readLine(); - while(line != null) - { - bodyBuilder.append(line); - line = reader.readLine(); - if(line != null) - bodyBuilder.append('\n'); + try { + String line = reader.readLine(); + while(line != null) { + bodyBuilder.append(line); + line = reader.readLine(); + if(line != null) { + bodyBuilder.append('\n'); + } + } + body = bodyBuilder.toString(); + } finally { + reader.close(); } - body = bodyBuilder.toString(); } } // IOException can leave connection object in a bad state, so catch all exceptions. @@ -760,8 +761,10 @@ public class FileTransfer extends CordovaPlugin { if (connection.getContentEncoding() == null || connection.getContentEncoding().equalsIgnoreCase("gzip")) { // Only trust content-length header if we understand // the encoding -- identity or gzip - progress.setLengthComputable(true); - progress.setTotal(connection.getContentLength()); + if (connection.getContentLength() != -1) { + progress.setLengthComputable(true); + progress.setTotal(connection.getContentLength()); + } } inputStream = getInputStream(connection); } @@ -794,9 +797,21 @@ public class FileTransfer extends CordovaPlugin { Log.d(LOG_TAG, "Saved file: " + target); // create FileEntry object - JSONObject fileEntry = FileUtils.getEntry(file); - - result = new PluginResult(PluginResult.Status.OK, fileEntry); + FileUtils filePlugin = (FileUtils)webView.pluginManager.getPlugin("File"); + if (filePlugin != null) { + JSONObject fileEntry = filePlugin.getEntryForFile(file); + if (fileEntry != null) { + result = new PluginResult(PluginResult.Status.OK, fileEntry); + } else { + JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, connection); + Log.e(LOG_TAG, "File plugin cannot represent download path"); + result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error); + } + } else { + Log.e(LOG_TAG, "File plugin not found; cannot save downloaded file"); + result = new PluginResult(PluginResult.Status.ERROR, "File plugin not found; cannot save downloaded file"); + } + } catch (FileNotFoundException e) { JSONObject error = createFileTransferError(FILE_NOT_FOUND_ERR, source, target, connection); Log.e(LOG_TAG, error.toString(), e); From 0f84287df03e7372eebe1d8620f8a78bb4900b4e Mon Sep 17 00:00:00 2001 From: James Jong Date: Thu, 13 Mar 2014 09:27:01 -0400 Subject: [PATCH 03/10] CB-6212 iOS: fix warnings compiled under arm64 64-bit --- src/ios/CDVFileTransfer.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ios/CDVFileTransfer.m b/src/ios/CDVFileTransfer.m index f19bece..1e62438 100644 --- a/src/ios/CDVFileTransfer.m +++ b/src/ios/CDVFileTransfer.m @@ -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]; From 653ec00fa65528afba0a203f364600f8999ccc9f Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Fri, 21 Mar 2014 11:09:50 -0400 Subject: [PATCH 04/10] [ios] Cleanup extra semicolons --- src/ios/CDVFileTransfer.h | 2 +- src/ios/CDVFileTransfer.m | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ios/CDVFileTransfer.h b/src/ios/CDVFileTransfer.h index aea9b2d..9c4bcf1 100644 --- a/src/ios/CDVFileTransfer.h +++ b/src/ios/CDVFileTransfer.h @@ -84,4 +84,4 @@ extern NSString* const kOptionsKeyCookie; @property (nonatomic, strong) CDVFileTransferEntityLengthRequest* entityLengthRequest; @property (nonatomic, strong) CDVFile *filePlugin; -@end; +@end diff --git a/src/ios/CDVFileTransfer.m b/src/ios/CDVFileTransfer.m index 1e62438..e35e262 100644 --- a/src/ios/CDVFileTransfer.m +++ b/src/ios/CDVFileTransfer.m @@ -492,9 +492,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 { @@ -765,4 +765,4 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream) return self; } -@end; +@end From 449df558480b12afc048af01138be7c0d4f8699a Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Fri, 21 Mar 2014 11:22:46 -0400 Subject: [PATCH 05/10] [ios] Cast id references to NSURL to avoid compiler warnings (Fixes: apache/cordova-plugin-file-transfer#18) --- src/ios/CDVFileTransfer.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ios/CDVFileTransfer.m b/src/ios/CDVFileTransfer.m index e35e262..3753993 100644 --- a/src/ios/CDVFileTransfer.m +++ b/src/ios/CDVFileTransfer.m @@ -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]]; @@ -646,7 +646,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream) 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]; + NSString* filePath = [self.target hasPrefix:@"/"] ? [self.target copy] : [(NSURL *)[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"]]; From 223d08626df36c0f386af3fe609d0a36c450d6d9 Mon Sep 17 00:00:00 2001 From: torrmal Date: Wed, 26 Mar 2014 11:58:26 -0400 Subject: [PATCH 06/10] [CB-5175] CDVFileTransfer asynchronous download (Fixes #24) Since download can take time, for it to be non-blocking, moved the call to a separate thread. --- src/ios/CDVFileTransfer.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ios/CDVFileTransfer.m b/src/ios/CDVFileTransfer.m index 3753993..d87bb94 100644 --- a/src/ios/CDVFileTransfer.m +++ b/src/ios/CDVFileTransfer.m @@ -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 From 2309e0e76ca7f4db63e273be75dfd7332b6eb824 Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Fri, 28 Mar 2014 10:36:01 -0400 Subject: [PATCH 07/10] iOS: Fix error where files were not removed on abort --- src/ios/CDVFileTransfer.m | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/ios/CDVFileTransfer.m b/src/ios/CDVFileTransfer.m index d87bb94..a1eeef2 100644 --- a/src/ios/CDVFileTransfer.m +++ b/src/ios/CDVFileTransfer.m @@ -587,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 @@ -612,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 *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; @@ -642,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 *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 *)[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]; From f2e56a2ac0ee85de15e1c95eaae2edcbc1c3f134 Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Tue, 8 Apr 2014 16:18:01 -0700 Subject: [PATCH 08/10] CB-6422 [windows8] use cordova/exec/proxy --- www/windows8/FileTransferProxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/windows8/FileTransferProxy.js b/www/windows8/FileTransferProxy.js index 5c09805..fae6533 100644 --- a/www/windows8/FileTransferProxy.js +++ b/www/windows8/FileTransferProxy.js @@ -117,4 +117,4 @@ module.exports = { } }; -require("cordova/windows8/commandProxy").add("FileTransfer",module.exports); +require("cordova/exec/proxy").add("FileTransfer",module.exports); From 9b85ae122aa722d059cafd2719cb2e32f250259a Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Wed, 16 Apr 2014 16:17:53 -0400 Subject: [PATCH 09/10] CB-6460: Update license headers --- plugin.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plugin.xml b/plugin.xml index 842081a..552e588 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,4 +1,23 @@ + + Date: Thu, 17 Apr 2014 10:53:20 -0400 Subject: [PATCH 10/10] CB-6452 Updated version and RELEASENOTES.md for release 0.4.3 --- RELEASENOTES.md | 13 +++++++++++++ plugin.xml | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 34da2ff..e982549 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -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 diff --git a/plugin.xml b/plugin.xml index 552e588..a4f4346 100644 --- a/plugin.xml +++ b/plugin.xml @@ -21,7 +21,7 @@ + version="0.4.3"> File Transfer Cordova File Transfer Plugin Apache 2.0