Skip to content

Commit 4465a77

Browse files
author
Remigiusz Jackowski
committed
Added callback to process successful server response.
1 parent a9879d8 commit 4465a77

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ grunt.initConfig({
4242
},
4343
data: {
4444
someKey: 'some value'
45+
},
46+
onComplete: function(data) {
47+
console.log('Response: ' + data);
4548
}
4649
},
4750
src: '<%= yeoman.dist %>/dist.zip',
@@ -87,6 +90,12 @@ DefaultValue: `{}`
8790

8891
Headers to send along with your HTTP request. For example, a lot of API require the Authentication to be sent through the Headers.
8992

93+
#### options.onComplete
94+
Type: `Function`
95+
DefaultValue: `function(data) {}`
96+
97+
Callback used to process server's response. For example, when server returns id of uploaded file you need to process afterwards.
98+
9099
#### src
91100
Type: `String`
92101
Default value: `''`

tasks/http_upload.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ module.exports = function(grunt) {
2323
rejectUnauthorized: true,
2424
method: 'POST',
2525
headers: {},
26-
url: ''
26+
url: '',
27+
onComplete: function(data) {}
2728
});
2829

2930
grunt.verbose.writeflags(options, 'Options');
@@ -61,6 +62,7 @@ module.exports = function(grunt) {
6162
}).on('complete', function(data, response) {
6263
if (response !== null && response.statusCode >= 200 && response.statusCode < 300) {
6364
grunt.log.ok('Upload successful of "' + filepath + '" as "' + field + '" - ' + options.method + ' @ ' + options.url);
65+
options.onComplete(data);
6466
} else if (response !== null) {
6567
grunt.fail.warn('Failed uploading "' + filepath + '" as "' + field + '" (status code: ' + response.statusCode + ') - ' + options.method + ' @ ' + options.url);
6668
} else {

0 commit comments

Comments
 (0)