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.