-
Hello! Thanks for a great library! Anyone know if there is a way to add a JSON body for use with POST request when initiating a download? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
hello @bkervaski , sadly not possible for the moment, i will take note to add this in future versions, for now i can suggest a workaround you could for the moment, override the __start function inside the library and add the write function of the request const { DownloaderHelper } = require('node-downloader-helper');
const data = JSON.stringify({
todo: 'Buy the milk'
});
const dl = new DownloaderHelper('my_url', __dirname, {
method: 'POST',
body: data, /// WORKAROUND
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
} } );
//------------- > WORKAROUND
dl.__start = function(){
if (!this.__isRedirected &&
this.state !== this.__states.RESUMED) {
this.emit('start');
this.__setState(this.__states.STARTED);
}
// Start the Download
this.__response = null;
this.__request = this.__downloadRequest(this.__promise.resolve, this.__promise.reject);
// Error Handling
this.__request.on('error', this.__onError(this.__promise.resolve, this.__promise.reject));
this.__request.on('timeout', this.__onTimeout(this.__promise.resolve, this.__promise.reject));
this.__request.on('uncaughtException', this.__onError(this.__promise.resolve, this.__promise.reject, true));
this.__request.write(this.__opts.body); // WORKAROUND
this.__request.end();
}
dl.on('end', () => console.log('Download Completed'))
dl.start(); i didnt try this, so not sure it would work, but that would be how i would implemented in the library later when i have the time |
Beta Was this translation helpful? Give feedback.
-
Released on |
Beta Was this translation helpful? Give feedback.
hello @bkervaski , sadly not possible for the moment, i will take note to add this in future versions, for now i can suggest a workaround
you could for the moment, override the __start function inside the library and add the write function of the request