Hey guys!
Hope everyone is doing great.
I need to upload different files extensions in my application, but I’m facing difficulties with that. I need to work with .prm, .dlg and .bin files, but when I use st.file_uploader, it returns me type ‘application/octet-stream’.
In the case of octet-stream, that’s the general mime type for arbitrary data that don’t have a more specific definition. Ultimately, it should work the same, as underneath it’s all bytes of data.
Hi, @randyzwitch!
I apologize for my superficial explanation and late response.
I’m working on developing a Pylinac web application with streamlit. Pylinac is a Python library to analyze the images and datasets commonly used by therapy medical physicists in the course of their routine linac QA. One of it’s modules, Log Analyzer uses .bin and .dlg type of files. I ran the ‘Tlog.bin’ file in a jupyter notebook and worked just fine with log_analyzer.TrajectoryLog class. But when I tried to use it with st.file_uploader returned this error message: ’ TypeError: expected str, bytes or os.PathLike object, not UploadedFile '.
The code screenshot and error message are below.
When you get an issue about UploadedFile, that’s because that is the class name we define within Streamlit. To make the data accessible to other Python programs, please see the Example section in our docs:
Because different libraries expect different sorts of data inputs, unfortunately we can’t make this portion more seamless.
Thanks for your help @randyzwitch!
I’ve already tried reading the file, but then this happened (screenshot) and the app just couldn’t work. I believe it won’t be possible to add this module to the app, unfortunately.
I recently helped someone facing a similar issue.
To solve it, instead of passing the file directly to the function, I first saved it to the disk using shutil library.
Here is a sample code for it:
if file is not None:
# save the uploaded file to disk
with open("Tlog.bin", "wb") as buffer:
shutil.copyfileobj(file, buffer)
tlog2 = log_analyzer.TrajectoryLog("Tlog.bin")
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.