Saving base64 to pdf file

Hey Bubble Crew,

I want to save a pdf as a file in the bubble database rather than the base64 response I get from an API connector so I can then attach to an email and send. I don’t want to use a paid plugin as it seems something really simply achieved - just a bit elusive to me right now.

The following javascript works perfectly in the browser downloading the pdf file returned from the API call but I just don’t know how to achieve this in the backend?

Also, less important to me - is there a way to download a base64 file if it is stored as text in the database?

THIS IS JAVASCRIPT CODE THAT WORKS IN THE BROWSER - ALLOWING ME TO DOWNLOAD THE PDF FROM A BASE64 RESPONSE

let a = document.createElement(“a”);
let data64=“Result of step 1 (PDF Generator - p…)'s response”;
a.href = “data:application/octet-stream;base64,” + data64;
a.download = ‘filename.pdf’;
a.click();
console.log(a);

any help greatly appreciated.

Hey Morgan,

The “Bubble Back End Utilities” plugin has an action “Write from Base 64”, it is supposed to save any base 64 encoded bytes to Bubble’s Amazon S3 and return the created file. Maybe you can use that one.

If the solution above does not work for you, I just built something similar using n8n.io, an open source alternative to Integromat/ Zapier etc…

Let me know if you need some info.

1 Like

Thanks for your response. I’ll check out that plugin. n8n looks interesting too - for lots of things, how do you find it compared to zapier and integromat / parabola etc?

No problem. N8N is less polished than Zapier and has less integrations (but it’s easy set up API’s). Integromat and Parabola i don’t have experience with. The pricing n8n offers is better.

You can use the open source version which you’ll have to install, host and maintain yourself or just use the cloud version.

Using N8N is a joy, it’s easy to build and debug. Using custom code is also easy.

Hi morgan,

Thank you for your post, I am trying only to download the PDF from an encoded or decoded Base64. I tried with your script but it is not working. Could you give me a bit mre informatioin on how it works.

I have seen on other threads that this seems to work.

Cordially,
Hervé

Yup that was exactly the use case I wrote those actions for. We are doing a lot of raw email and PDF splitting and parsing so we needed to move the byte streams around the Bubble back-end as JSON safe data.

Long term, once we start hitting serious bottlenecks on the Bubble back-end, we are going to offload that processing to our own AWS lambda service that just returns the final products.

This topic was automatically closed after 70 days. New replies are no longer allowed.