Hey everyone, I need help with this:
I receive a report via API as an HTML file and save it in my database through an API call to my own app. But when we try to open the report, it’s automatically downloaded, instead of opening in the browser (as expected for an HTML file). This is happening with every user, using multiple PC and browser settings.
After doing some research, my best guess is that the browser isn’t able to identify the file as HTML due to a file type/MIME issue, probably because the file is being saved through an API call and not through a file uploader, for example.
So my question is: Is there a way to set file metadata, specifically the file type through the API call? Or do you have a different solution for that issue?
This is how the API call that creates the file looks like:
If you download the file, and click on it, does it open the html file?
If it opens properly then there’s nothing wrong with files mime type. The MIME is passed along with the file it’s not something you can change when doing the API call.
<a> tag ( a link ).
I think the way to do this properly is with an iframe to display the file.
Thanks for the response, mate.
Yes, it opens properly after downloading the file, but what is weird is that if file is manually uploaded (using a file uploader input), the same feature will open the file in a new tab, this led me to think that the problem was related to how the file is identified by Bubble and the browser when it comes from the API.
I’m not using a plug-in or custom JS to display it, just Bubble’s native link element holding the file’s URL with the option to open it in a new tab enabled. I’ll try different ways to display it.
I’m not sure why that’s happening but i would definitely suggest using an iframe, that way you can just display it on the page and they can download it if they feel like it.
Iframes also accept and can display the file encoded as a data uri (encoded as base 64). I’m not sure if you control the server you’re calling, if you do, just send over the file as a data uri instead it will be a lot easier to display it
Sounds good, I’ll implement the iframe solution, it might end up being even better than the original feature. Thanks Jonah!