Forum Academy Marketplace Showcase Pricing Features

Change Alert Message when upload file

Hi, When i need to upload files but create an alert if the file size is>5 MB,
the alert result will get your file size very large.

How can I do that in fileUploader plugin in bubble?

It’s a bit janky but here goes. You’ll need to run it server side.

When (File Uploader's value:encoded in base64: number of characters * 0.75) / 1024 > 5000 do whatever you want to do when the file size > 5MB.

Basically, we encode it in base64, count the number of characters of the Base64 string. Base64 is about 33% larger than the original so we multiply by 0.75 first. That gives us the number of bytes. Divide by 1024 to get the value in kilobytes. 5000 KB is (about) 5MB.

You can also use @jonah.deleseleuc’s Better Uploader plugin:

2 Likes

Yeah, that’s a good solution in theory but in practice it can get you in trouble depending on the situation. The reason is become when you encode in base64 the file size increases due to the encoding. So when you’re checking the file size you’re going to get an inaccurate reading, even if you try to guesstimate the 33% difference. It also takes time to calculate that every time, especially if you’re dealing with multiple files.

In most situations it probably won’t matter because the difference is not really big but i you’re desperate to save space, increase load times or working with strict APIs then this might not be the best solution.

My plug-in better Uploader just checks the metadata of the file to see how big it is. It’s also less jank to do

1 Like

That’s a good point I hadn’t considered - I only tested with files a few hundred kilobytes.

1 Like