NEW
Chat with Your PDFs Now!
Read More ↗

Upload a PDF to CloudPDF from your Node.js app

You can upload a to CloudPDF through your Node.js app or you can upload a document through the CloudPDF dashboard. In this article we will explain how to upload a document through your node.js app. If you are looking to upload a document through the dashboard you can read the article: Upload a document

Inside your Node.js app you can choose to upload your file through a file path or a file stream.

1. Upload a document from file path

import { CloudPDF } from '@openbook/cloudpdf-node'
cloudPDF.uploadDocumentFromFilePath('./yourfile.pdf', {
type: 'upload',
public: true,
exp: (new Date().getTime() + 60 * 60 * 1000)/1000
}).then((body) => {
//your code
}).catch((error) => {
//your error handling
})

2. Upload a document from stream

import { CloudPDF } from '@openbook/cloudpdf-node'
import { createReadStream } from 'fs';
const readable = createReadStream('./yourfile.pdf');
cloudPDF.uploadDocumentFromStream(readable, {
type: 'upload',
public: true,
exp: (new Date().getTime() + 60 * 60 * 1000)/1000
}).then((body) => {
//your code
}).catch((error) => {
//your error handling
})