In my dash app, I want to upload a voice file(wave or mp3 etc) and I want to process the contents of the file in the backend. Is it possible through the dcc.Upload component? I am also using the tabs functionality in the same app. So, I have installed dash-core-components-0.13.0rc5. Is the upload component supported in this version of dash-core-components? I am not able to use the upload component in this version.
@chriddyp - Please suggest
I don’t see why it wouldn’t be.
dcc.Upload doesn’t restrict any data types. Have you tried this?
See Dash Tabs component by chriddyp · Pull Request #74 · plotly/dash-core-components · GitHub
Thank You. I was able to achieve what I was expecting after an initial hiccup. I had to decode the ‘contents’ into a wav file before processing.
how to decode the contents into a wav file.
can you help me kmrambo
@akhil_babu Can you post this question on stackoverflow and share me a link to it over here so that I would be able to answer this?
‘utf-8’ codec can’t decode byte 0xf8 in position 5: invalid start byte
sorry I didn’t have the stackoverflow account
Here’s the solution to handle mpeg as well as wav audio files inside your callback:
data = contents.decode('utf-8')
rawdata = data.split(',')
if filetype == 'mpeg':
fh = open("/Yourpath/audio.mp3", "wb")
elif filetype =='x-wav':
fh = open("/Yourpath/audio.wav", "wb")
just change the code a little bit
data = contents.**encode().**decode(‘utf-8’)
rawdata = data.split(’,’)
others are all good. so looks like the dcc.upload transfer data in str protocol