Does bubble have any temp folder to to use fs.createWriteStream in the plugin builder?
Hey,
Looks like it works properly.
You also can create and upload files:
http://s3.amazonaws.com/appforest_uf/f1560503091064x127426841973505620/hello_world.txt
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?
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}});
doc.pipe(file);
//PDF Data Goes here
doc.end();
file.on("finish", function(){
let data = {fileData: fs.createReadStream('testfile.pdf')}
fetch('https://webhook.site/acf4d875-6544-44b2-9744-c0067f6e5258', { 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.pipe(file)// OCODE and DCODE
doc.font(âHelvetica-Boldâ)
doc.fontSize(15)
doc.text(âDXB - DXBâ, 140, 22,{width: 143, align: ârightâ});
// Recipient Label
doc.fontSize(10)
doc.text(âRECEIPIENTâ, 10, 60, {width: 125, align: âleftâ});
// Recipient Full Name
doc.font(âHelveticaâ)
doc.fontSize(8)
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â});doc.end();
file.on(âfinishâ, function() {
fs.readFile(âmyPDF.pdfâ, âbase64â, function(err, data) {
if(err){console.error(err)};
fetch(âhttps://labelsapp.bubbleapps.io/version-test/api/1.1/obj/user/1562434545944x340606601571464600â, {
method: âpatchâ,
headers: {âAuthorizationâ: âBearer fedb18121f0e13191a8a89b1e0b5b74dâ, âContent-Typeâ: âapplication/jsonâ},
body: JSON.stringify({
FILE:{
filename: âmyLabels.pdfâ,
contents: data,
private: false
}
})
})
.catch(err => console.log(err));
});
});}
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.
https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-logging.html
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.
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!