Integrating Cloudinary File picker widget for uploading PDF files -- Yaayyyy!

Hi Thunkers,

I have been working on a file picker to allow Thunkable to select pdf (and all other file types) from sources such as local device, google drive, Onedrive, Facebook shutter stock etc…

I have been able to accomplish this on both Android and IOS. Here is where I am up to and how I have done it so far…

What you will need:

  1. Free tier Cloudinary account
  2. Free tier Firebase account
  3. Simple editor (I like Visual Studio Code but Note++ will do.)

The Thunkable modules we will use are the web viewer “set url” and “when web viewer receives message”.

First, set up your Cloudinary account and an Upload preset (there is a lot of existing instructions on this so I won’t get into it here)

Create the following file using an editor (I have slightly edited this but I am not a programmer so I am waiting for the experts to have a look.
<–!DOCTYPE html>
<–html lang=“en”>
<–head>
<–meta charset=“UTF-8”>
<–meta name=“viewport” content=‘width=device-width, initialscale=1.0, maximum-scale=1.0, user-scalable=0’>
<–title>JavaScript File Upload
<–/head>
<–body>
<–!--button id=“upload_widget” class=“cloudinary-button”>Upload files
<–script src=“https://thunkable.github.io/webviewer-extension/thunkableWebviewerExtension.js” type=“text/javascript”><–/script>
<–script src=“https://widget.cloudinary.com/v2.0/global/all.js” type=“text/javascript”><–/script>
<–script type=“text/javascript”>
var myWidget = cloudinary.createUploadWidget({
cloudName: ‘replace this with yours’,
uploadPreset: ‘ml_default’ //I used the default but changed to unsigned.
}, //currently using unsigned Preset
(error, result) => {
if (!error && result && result.event === “success”) {
console.log('Done uploading…: ', result.info);
ThunkableWebviewerExtension.postMessage(result.info.secure_url);
myWidget.close();//
myWidget.open()
}
});
myWidget.open();
/*
document.getElementById(“upload_widget”).addEventListener(“click”, function(){
ThunkableWebviewerExtension.postMessage(“hello eddies world”);
}, false);
*/
<–/script>
<–/body>
<–/html>

Note: I suggest you research and produce you own file but if you do decide to play around using the above code then remove all ‘–’ that I have included to enable code to be displayed in this post.

save the file and call it anything you like but with a .HTML extension.

Upload the file to Firebase Storage. (I mean the STORAGE and not the realtime database)

Get the download link from Firebase Storage for this file. (File location - access Token).

placing this link into any browser will open the html file and hence the widget.

I have managed to open and use the widget successfully from within Thunkable simply by using the Web viewer and setting the link to the access token of my firebase stored html file.

I am able to select any file type from local or cloud sources and it uploads to my Cloudinary account. I can also preset transformations but that’s another thread I think. I have added a post message on success in my html javascript which returns the url of the uploaded file in Cloudinary. I can now do what I like with the file including setting up Node JS functions in Firebase to tidy up the assets into users folders although most of you will use Thunkable blocks to manipulate this which is also fine. The widget will also handle video.

From here I am seeking some input from the experts out there.

I hope this has helped some of you who have been battling with uploading pdf files into Thunkable. Using the Cloudinary widget does this and much much more :grinning:

5 Likes

Thank you. You just opened my eyes on a good source of integrating my App with a website. Not file picking but communicating back and forth using their connector/pligin. I was trying to solve the issue of where to save the html file and have it accessible and you solved it.

Many thanks :laughing:

3 Likes

I look forward to trying this out!

3 Likes

Hey eddy! Awesome work. Can you share a working example with api keys removed?

3 Likes

Thanks for the encouragement guys :grinning:

@darren I follow your channel and I would love for you to take what I have done and turn it into a demonstration. Let’s get it working better first.

Today I spent more time on this and it looks really promising. I have modified my code slightly so that I let the widget know to upload the file to particular users folder (my project uses Firebase UID for each user throughout all components). The folder will be created by Cloudinary if it doesn’t already exist. Effectively I now have an archived asset library for each user which can be added to using this widget for any file type from any source.

I have noticed however that two of the features do not show content through Thunkable when they do through other browsers. These are Namely the dropbox and Instagram components of the cloudinary widget. All others seem to be smooth including Facebook, Local device, OneDrive etc… All file types are uploading and I have been able to add the returned uploaded url’s to UID lists in the Firebase RTDB so we can pretty much do what we like with them after this.

At first I though the issue with Dropbox and Instagram was iframes but I have created an i-frame html for testing purposes and all features do work well in browsers through iframe. It hence must be something related to Thunkable web viewer. It isn’t a big deal to turn these two sources off and just use the widget with the remaining capabilities which of course include the main one of local drive allowing all file types from the local device.

Anyway, I will tidy up what I have been working on the last couple of days and share the project in more detail shortly.

1 Like

Looking forward to gauging the interest in this.

Thunkable:
https://x.thunkable.com/projectPage/5f6864092fa8432dba66427a

html: (as txt file)
https://firebasestorage.googleapis.com/v0/b/luco-ffeb6.appspot.com/o/Public_Files%2FThunkable_Cloudinary-Widget.txt?alt=media&token=51021586-2522-4126-b340-46d656da47e5

Node js (Optional for programatically deleting assets from Cloudinary instead of using Console)
https://firebasestorage.googleapis.com/v0/b/luco-ffeb6.appspot.com/o/Public_Files%2FNodeJS_Firebase-db_Cloudinary-Sync.js?alt=media&token=5da7626b-61df-441e-9a04-94063a63d361

2 Likes

Hi
I have seen your video on youtube and copied the project you handle, but by some reason the assets that I upload to my cloudinary library is not showing on the app; it works fine when I select the image and the uploads it to my cloudinary library, but it will not be shown when I press the buttons small, medium o large on thunkable app; any ideas or sugestions. Thanks,

Hi @boris.hernandez,

This was one of my more ambitious projects and I think I got a little zealous with the blocks. Looking at it now, I would probably re-do much of the viewer part. I concentrated more on a file-picker that doesn’t use Cloudinary at all but that is another project entirely.

I am glad you managed to use the filepicker and upload to your cloudinary account but in order for me to consider your issue, I really need to know if you are populating the firebase database node as you upload. It is only then that you can start to look at fetching the cloudinary urls from the RTDB and display them in some arbitrary viewer in Thunkable.

eddie,

this technic still relevant or it has latest one? i am looking solution for upload file to cloudinary or other cloud storage and then place link to airtable so user can download the files later.

hi @ozel1978,

Please see my response above to boris.

There are a few caveats to the methods shown in this thread:

  1. Cloudinary will not allow pdf with their free tier accounts unless prior permission is requested. While this is a simple email correspondence confirming non-malicious intent, it can be a little annoying.
  2. Office documentation such as doc, ppt and xls etc… requires a Cloudinary third party plugin that has a low free tier quotas.

I have managed to create a similar method without using Cloudinary which relies on NodeJS and Javascript HTML using Thunkable web viewer. It uses Firebase db and Firebase Storage instead of Cloudinary and worked very well but please do not ask me for this as it is not a cut-paste type of project.
A minimum intermediate level in javascript and NodeJS would be required and it uses javascript Canvas and PDF.js.

I have spent the past few months rewriting my Thunkable app using Javascript/HTML/CSS in Cordova for IOS and android app.

My journey has taught me much respect for the Thunkable developers as I now see the problems and caveats they face however I strongly suggest that anyone with Coding skills or those prepared to learn to code look at (non-block) alternatives to Thunkable before spending one year on a project only to find that the beta stage of testing your app is more about the Thunkable bugs than your actual project at hand. I mainly came unstuck with event listeners among other essential tasks. Thunkable Functions are also painfully slow.

In having said this, I am a strong advocate for Thunkable for anyone that wants to create a relatively simple app without learning to code.

best of luck.

3 Likes

Hello. I copied your HTML into VSCode and changed the cloud name also to my corresponding cloudinary cloud name but when i save it as .html and open it, there is a blank screen with no widget…Please can you advise me and tell me how to work around it?
I just want users to upload their PDF files… i don’t want to display it back into thunkable… its like a microsoft forms thing kind of- just upload the pdf from the device and save it to cloudinary
Thank you.
Regards.