-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba58d15
commit 6804bb7
Showing
1 changed file
with
38 additions
and
13 deletions.
There are no files selected for viewing
51 changes: 38 additions & 13 deletions
51
JavaScript/Endpoint Examples/Multipart Payload/request-status.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
const axios = require("axios"); | ||
const FormData = require("form-data"); | ||
const fs = require("fs"); | ||
|
||
let config = { | ||
method: "get", | ||
maxBodyLength: Infinity, // set maximum length of the request body | ||
url: "https://api.pdfrest.com/request-status/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", | ||
headers: { "Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } | ||
|
||
const apiKey = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // Replace with your API key | ||
const pathToFile = "/path/to/file.pdf"; | ||
|
||
let bmpRequestData = new FormData(); | ||
bmpRequestData.append("file", fs.createReadStream(pathToFile)); | ||
|
||
let bmpConfig = { | ||
method: "post", | ||
maxBodyLength: Infinity, | ||
url: "https://api.pdfrest.com/bmp", | ||
headers: { | ||
"Api-Key": apiKey, | ||
"Response-Type": "requestId", // Use this header to get a request ID. | ||
...bmpRequestData.getHeaders(), | ||
}, | ||
data: bmpRequestData, | ||
}; | ||
|
||
// define configuration options for axios request | ||
axios | ||
.request(config) | ||
.then((response) => { | ||
console.log(JSON.stringify(response.data)); | ||
}) | ||
.catch((error) => { | ||
axios(bmpConfig) | ||
.then(bmpResponse => { | ||
console.log(JSON.stringify(bmpResponse.data)); | ||
const requestId = bmpResponse.data.requestId; | ||
let config = { | ||
method: "get", | ||
maxBodyLength: Infinity, // set maximum length of the request body | ||
url: `https://api.pdfrest.com/request-status/${requestId}`, | ||
headers: { "Api-Key": apiKey } | ||
}; | ||
axios.request(config) | ||
.then((requestStatusResponse) => { | ||
console.log(JSON.stringify(requestStatusResponse.data)); | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
}); | ||
}).catch(error => { | ||
console.log(error); | ||
}); | ||
}) |