/
pdf-with-added-attachment.js
35 lines (31 loc) · 1.19 KB
/
pdf-with-added-attachment.js
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
/**
* This request demonstrates how to add a file attachment to a PDF.
*/
var axios = require('axios');
var FormData = require('form-data');
var fs = require('fs');
// Create a new form data instance and append the PDF file and parameters to it
var data = new FormData();
data.append('file', fs.createReadStream('/path/to/file'));
data.append('file_to_attach', fs.createReadStream('/path/to/file'));
data.append('output', 'pdfrest_pdf_with_added_attachment');
// define configuration options for axios request
var config = {
method: 'post',
maxBodyLength: Infinity, // set maximum length of the request body
url: 'https://api.pdfrest.com/pdf-with-added-attachment',
headers: {
'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // Replace with your API key
...data.getHeaders() // set headers for the request
},
data : data // set the data to be sent with the request
};
// send request and handle response or error
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
// If you would like to download the file instead of getting the JSON response, please see the 'get-resource-id-endpoint.js' sample.