[SS Plugin action ] Best way for saving a file in bubble's filesystem

Update:

Right now i’m using @vini_brito’s PDF Conjurer approach ( i think is a great solution because it doesnt use the /savefile endpoint ), with a twist, that i think is more straightfoward for users (it doesnt have option for private files)


// makes a request to a custom WF that uploads a Base64 File
// function( string, stringB64, string, string)
  function uploadToBubble( upload_url, file_data, file_input, file_name ) {
        const file = {
        filename: file_name,
        contents: file_data
    };
    
    const uri = upload_url.startsWith('http') ? upload_url : 'https:' + upload_url;
    const method = 'POST';
    const body = { [file_input]: file };
    const json = true;
    
    const options = { uri, method, body, json };
    
    const response = context.request(options);
    
    const responseBody = JSON.stringify(response.body);
    
    const test = responseBody.match(/(https:)?\/\/.*?\.ics/);

    const url = test ? test[0].startsWith('http') ? test[0] : 'https:' + test[0] : "It wasn't possible to find the uploaded file URL"; 
    
    return url; 
    }
// it returns a key:value with the uploaded file url that is generated by a function inside the same action that create the file (in base64 format)

return {fileUrl: uploadToBubble( context.keys["upload_API"], base64data, context.keys["file_field"], 'invite.ics' )}

In the workflow, the plugin creates a B64 encoded file and exposes the url, that can be later used for file operations

The users set up the upload url in the plugin page instead of using a workflow and setting up the upload url each time.

At the end of the workflow i run a ‘garbage collector’ wf as stated here to get rid of unnecessary files in the DB (i need to send the file in an email and then get rid of it, so with this workflow it works like a temporary file)

Be sure to check and use @vini_brito PDF Conjurer plugin that is GREAT and is amazingly documented :star_struck:, it has been a great reference for this.

https://www.unlimitedbubbling.dev/docs_public