diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bc5c26..5251dc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v1.8.1 + +- Fixed #27: "uploadFile" method doesn't return data object on iOS (thanks Faisalali23 and laiyinjie) + ## v1.8.0 - Feature #33: response object contains response url diff --git a/package.json b/package.json index f686da3..21429b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-advanced-http", - "version": "1.8.0", + "version": "1.8.1", "description": "Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning", "scripts": { "testapp": "./scripts/build-test-app.sh && ./scripts/test-app.sh --ios --emulator", diff --git a/src/ios/CordovaHttpPlugin.m b/src/ios/CordovaHttpPlugin.m index 91449db..6f64cd9 100644 --- a/src/ios/CordovaHttpPlugin.m +++ b/src/ios/CordovaHttpPlugin.m @@ -366,7 +366,7 @@ } } progress:nil success:^(NSURLSessionTask *task, id responseObject) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; - [self handleSuccess:dictionary withResponse:(NSHTTPURLResponse*)task.response andData:nil]; + [self handleSuccess:dictionary withResponse:(NSHTTPURLResponse*)task.response andData:responseObject]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; diff --git a/test/app-test-definitions.js b/test/app-test-definitions.js index 18b3aab..7372e71 100644 --- a/test/app-test-definitions.js +++ b/test/app-test-definitions.js @@ -16,6 +16,19 @@ const helpers = { xhr.open('GET', url); xhr.send(); + }, + writeToFile: function (done, fileName, content) { + window.resolveLocalFileSystemURL(cordova.file.cacheDirectory, function (directoryEntry) { + directoryEntry.getFile(fileName, { create: true, exclusive: false }, function (fileEntry) { + fileEntry.createWriter(function (fileWriter) { + var blob = new Blob([ content ], { type: 'text/plain' }); + + fileWriter.onwriteend = done; + fileWriter.onerror = done; + fileWriter.write(blob); + }, done); + }, done); + }, done); } }; @@ -166,6 +179,7 @@ const tests = [ func: function(resolve, reject) { cordova.plugin.http.patch('http://httpbin.org/anything', [ 1, 2, 3 ], {}, resolve, reject); }, validationFunc: function(driver, result) { result.type.should.be.equal('resolved'); + result.data.data.should.be.a('string'); JSON.parse(result.data.data).json.should.eql([ 1, 2, 3 ]); } },{ @@ -200,6 +214,31 @@ const tests = [ result.data.name.should.be.equal('test.xml'); result.data.content.should.be.equal("\n\n\n\n\n\n \n \n Wake up to WonderWidgets!\n \n\n \n \n Overview\n Why WonderWidgets are great\n \n Who buys WonderWidgets\n \n\n"); } + },{ + description: 'should upload a file from given path in local filesystem to given URL #27', + expected: 'resolved: {"status": 200, "data": "files": {"test-file.txt": "I am a dummy file. I am used ...', + func: function(resolve, reject) { + var fileName = 'test-file.txt'; + var fileContent = 'I am a dummy file. I am used for testing purposes!'; + var sourcePath = cordova.file.cacheDirectory + fileName; + var targetUrl = 'http://httpbin.org/post'; + + helpers.writeToFile(function() { + cordova.plugin.http.uploadFile(targetUrl, {}, {}, sourcePath, fileName, resolve, reject); + }, fileName, fileContent); + }, + validationFunc: function(driver, result) { + var fileName = 'test-file.txt'; + var fileContent = 'I am a dummy file. I am used for testing purposes!'; + + result.type.should.be.equal('resolved'); + result.data.data.should.be.a('string'); + + JSON + .parse(result.data.data) + .files[fileName] + .should.be.equal(fileContent); + } } ];