-
-
Notifications
You must be signed in to change notification settings - Fork 323
Added progress callback for uploadFile #466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,7 +180,14 @@ module.exports = function init(exec, cookieHandler, urlUtil, helpers, globalConf | |
| break; | ||
| case 'upload': | ||
| var fileOptions = helpers.checkUploadFileOptions(options.filePath, options.name); | ||
| exec(onSuccess, onFail, 'CordovaHttpPlugin', 'uploadFiles', [url, headers, fileOptions.filePaths, fileOptions.names, options.connectTimeout, options.readTimeout, options.followRedirect, options.responseType, reqId]); | ||
| var hasProgressCallback = options.onProgress != null; | ||
| exec(function(resp) { | ||
| if (resp != null && resp.isProgress) { | ||
| options.onProgress(resp); | ||
| } else { | ||
| onSuccess(resp); | ||
| } | ||
|
Comment on lines
+185
to
+189
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please extract this inline handler into a function expression in lines 183ff for making it more readable. |
||
| }, onFail, 'CordovaHttpPlugin', 'uploadFiles', [url, headers, fileOptions.filePaths, fileOptions.names, options.connectTimeout, options.readTimeout, options.followRedirect, options.responseType, reqId, hasProgressCallback]); | ||
| break; | ||
| case 'download': | ||
| var filePath = helpers.checkDownloadFilePath(options.filePath); | ||
|
|
@@ -223,8 +230,8 @@ module.exports = function init(exec, cookieHandler, urlUtil, helpers, globalConf | |
| return publicInterface.sendRequest(url, { method: 'options', params: params, headers: headers }, success, failure); | ||
| }; | ||
|
|
||
| function uploadFile(url, params, headers, filePath, name, success, failure) { | ||
| return publicInterface.sendRequest(url, { method: 'upload', params: params, headers: headers, filePath: filePath, name: name }, success, failure); | ||
| function uploadFile(url, params, headers, filePath, name, success, failure, progress) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this work for the https://github.com/danielsogl/awesome-cordova-plugins/ wrapper? I think it could be a problem but not sure, because usually the last two arguments are meant to be |
||
| return publicInterface.sendRequest(url, { method: 'upload', params: params, headers: headers, filePath: filePath, name: name, onProgress: progress }, success, failure); | ||
| } | ||
|
|
||
| function downloadFile(url, params, headers, filePath, success, failure) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to check for falsey value here not for null, because it will be
undefinedif not provided.