Plugin fs.CreateWriteStream

Does bubble have any temp folder to to use fs.createWriteStream in the plugin builder?



Looks like it works properly.

You also can create and upload files:

1 Like

Thanks I’ll check it out.

Where are you getting the S3 URL from?

I’ve uploaded the file to the Bubble app.

Is it possible to upload the file within the plugin and return the URL as a value?

Yes, sure.

You can send a file to your Bubble app and then return the URL.

I cant seem to get it to send the API request. It also does not throw any errors

function(properties, context) {
const fetch = require('node-fetch');
const fs = require("fs");
const PDFDocument = require('pdfkit');

let file = fs.createWriteStream('testfile.pdf');    
let doc = new PDFDocument({layout: "portrait", size: [4 * 72, 6 * 72], margins:{top: 10, bottom: 5, left: 5, right: 5}});

    //PDF Data Goes here
    file.on("finish", function(){
     let data = {fileData: fs.createReadStream('testfile.pdf')}
     fetch('', { method: 'POST', body: JSON.stringify(data)})
    .then(res => res.json())
    .then(json => console.log(json));


Is it a async/await issue?

You need to fix your code. It doesn’t work as should be.
The best way is to test it in the code editor.

I moved the code over to my local machine and fixed it. It works perfectly fine from my machine but when executed on Bubble, nothing happens…

function(properties, context) {

const fetch = require(‘node-fetch’);
const PDFDocument = require(‘pdfkit’);
const fs = require(“fs”);

let file = fs.createWriteStream(“myPDF.pdf”);
let doc = new PDFDocument({layout: “portrait”, size: [4 * 72, 6 * 72], margins:{top: 10, bottom: 5, left: 5, right: 5}});

doc.text(“DXB - DXB”, 140, 22,{width: 143, align: ‘right’});
// Recipient Label
doc.text(“RECEIPIENT”, 10, 60, {width: 125, align: ‘left’});
// Recipient Full Name
doc.text(“Joe Smith”, {width: 125, align: ‘left’});
// Recipient Phone Number
doc.text("(415) 555-1234", {width: 125, align: ‘left’});
// Recipient Address Description
doc.text(“Mag 5 Boulevard”, {width: 125, align: ‘left’});
// Recipient Area and City
doc.text(“San Francisco, CA 94105”, {width: 125, align: ‘left’});


file.on(‘finish’, function() {
fs.readFile(‘myPDF.pdf’, ‘base64’, function(err, data) {
fetch(‘’, {
method: ‘patch’,
headers: {‘Authorization’: ‘Bearer fedb18121f0e13191a8a89b1e0b5b74d’, ‘Content-Type’: ‘application/json’},
body: JSON.stringify({
filename: ‘myLabels.pdf’,
contents: data,
private: false
.catch(err => console.log(err));


1 Like

Try to use Sync functions instead of Async.
Also, use the context.request(options) for making Sync requests.

I tired using async/await but it does not work on Bubble, it works all the time from my local machine. Does bubble not provide a way to see server side errors during the build of plugins?

If I remember correctly, the Bubble doesn’t provide it yet.
They are using Lambda for server-side plugins.

I had experience with Lambda in the past. There is a way to view logs created by console.log() function. They are available in the CloudWatch Logs.

It would be great if @Bubble will provide the possibility to view these logs. It is very hard to configure something without a way to view logs. :pensive:

BTW, you need to create files in the temp directory. For instance ('/tmp/myFile.pdf')

I gave up trying to build this on bubble. I just created it in Lambda and it works perfectly fine.

I’m using only Sync functions for the server-side plugins.

How do you define it to run Sync? I thought the Functions ran in the node.js environment which is all async and using the “await” inside the functions gives a syntax error in bubble editor

fs.readFile > fs.readFileSync

I’m converting Async functions into Sync ones in the case if it doesn’t support Sync.

It works very well!