Forum Academy Marketplace Showcase Pricing Features

Save returned file (PDF) to URL

I’m using the HTML2PDF.js library to create a plugin that lets users create PDFs of specific elements.

Using a server side action to get the output in Base64 format - see below for plugin code and console log.

Screenshot 2023-02-07 at 00.51.29

So I’m able to create the PDF and print it in the console in Base64 format… but am a bit lost as to where to go from here.

Any idea how I can save the created PDF down to a URL so users can access it (and save it to the database)?

I have read @jared.gibb’s excellent post on returning objects from plugins, but not quite sure how to apply it to my own situation.

First, according to your screenshot, your are running a client script and not server script.
You cannot use ACTION to do that directly in server script. You need to send the file to the Bubble file API.
In Client side script, you can use context.uploadContent() function (check doc)
Finally, in element this is done with instance.uploadFile or with context too.

1 Like

Thanks @Jici this was really helpful - and you were correct, I was running a client script not a server script (silly mistake on my part).

If I use the context.uploadContent() function in my client script, any idea what’s the best way to then access the created URL?

I’ve seen suggestions elsewhere on forum to use an exposed state to store the URL, but I don’t think that will work if I’m running a client script (as I won’t have access to the “instance” property)?

There’s no way in client script to return value. You have two options: use element and return in a state the url of the uploaded file or switch to server side script to return the url in returned value

1 Like

@Jici thank you so much again - you’ve been incredibly helpful!

Thanks to your direction, I’ve figured out how to save the PDFs down to the database and generate a corresponding URL,

However, I’m getting an “AccessDenied” code when I try to view the PDF via the relevant URL link - see below:

I realise this is veering away from my original query, but any idea why I might be getting this message? Do I need to configure something with AWS S3 perhaps?

1 Like

Thanks for the post @doug.burden - unfortunately I’m not sure it’s quite what I’m looking for.

To provide more detail - I have uploaded the below files to the bubble database using my plugin - you can see the associated URL in the bottom-left hand corner of the image.

When I click on the URL in this section of the database, the PDF automatically gets downloaded to my desktop.

However, what I really want is for users to be able to access the PDF on their internet browser.

So I’ve saved down a URL for each PDF in the plugins exposed state, which allows my plugins users to save it down to their own database.

Plugin code to save URL to exposed state
Screenshot 2023-02-07 at 20.51.57

Saving the URL to the bubble database
Screenshot 2023-02-07 at 20.53.43

However, whenever I try to access the saved down URL via a bubble app - I get this error:

Any further assistance would be greatly appreciated :slight_smile:

From my own experience, any time I got that xml error it was because the link was corrupted or incomplete.

How are you navigating your User to this file?

1 Like

got it sorted in the end @doug.burden - solution was to slightly modify the first argument passed through for the uploadContent function

Thanks for all your help :slight_smile:

1 Like