-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathget_result_file_stream.js
More file actions
40 lines (32 loc) · 1.06 KB
/
get_result_file_stream.js
File metadata and controls
40 lines (32 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* eslint-disable no-console */
// set your api secret or token
var convertapi = require('../lib')(process.env.CONVERT_API_SECRET);
// Example of converting Web Page URL to PDF and reading file data as string
// https://www.convertapi.com/web-to-pdf
var fromFormat = 'web';
var conversionTimeout = 180;
var https = require('https');
var Stream = require('stream').Transform;
var params = {
Url: 'https://en.wikipedia.org/wiki/Data_conversion',
FileName: 'web-example'
};
convertapi.convert('pdf', params, fromFormat, conversionTimeout)
.then(function(result) {
result.files.forEach(function(resultFile) {
console.log("Result url: " + resultFile.url);
https.get(resultFile.url, function(response) {
var stream = new Stream();
response.on('data', function(chunk) {
stream.push(chunk);
});
response.on('end', function() {
var data = stream.read()
console.log("Downloaded data size: " + data.length);
});
});
});
})
.catch(function(e) {
console.error(e.toString());
});