Skip to main content

I’m trying to upload a .lucid file to lucidchart to create a document, using node.js.  The examples here
https://github.com/lucidsoftware/sample-lucid-rest-applications
Either are python, or do not upload files.

The tricky bit is setting the ‘content-type’ of the individual file to ‘x-application/vnd.lucid.standardImport’ (A stupid requirement, FYI).  Python has an easy syntax.  Node.js?  Not so much.  I’ve tried adding a blob 

        const blob = new Blob(cmyzipfilestream], { type: 'x-application/vnd.lucid.standardImport' })

 

but I get some cryptic error about ‘source.on is not a function’.

Does anyone have an example of *working* Node.js code that uploads a .lucid file to lucidchart via a POST request?

Thanks

Hello Johnktejik,

I was able to update the content-type with the following code below.
 

const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');

// Create a FormData object
const formData = new FormData();
formData.append('file', fs.createReadStream('/file/path'), {
contentType: 'x-application/vnd.lucid.standardImport'
}); // Adjust file path
formData.append('product', 'lucidchart'); // Product name


// Send the request
axios.post('https://api.lucid.app/documents', formData, {
headers: {
'Authorization': 'Bearer <oauth token or api key>',
'Lucid-Api-Version': '1',
...formData.getHeaders(),
},
})
.then(response => {
console.log('File uploaded successfully:', response.data);
})
.catch(error => {
console.error('Error uploading file:', error);
});

Reply