xeus-python
xeus-python copied to clipboard
FileUpload widget received data is corrupted
When running this in a cell in a Python3 kernel, then the uploaded file is saved correctly in a local file:
from ipywidgets import FileUpload
uploader = FileUpload()
notebookDir = "c:/Users/andra"
def _handle_upload(change):
metadata = uploader.metadata[0]
uploaded_filename = metadata['name']
import os
filename = os.path.join(notebookDir, uploaded_filename)
content = uploader.value[uploaded_filename]['content']
with open(filename, 'wb') as f: f.write(content)
print('Uploaded {0} ({1} bytes)'.format(filename, metadata['size']))
uploader.observe(_handle_upload, names='data')
display(uploader)
When I run this in xeus-python then the file that is written out is corrupted. For text-like files extra characters may appear at the end of the file (reproducible with ProstateMeanShape.stl). For binary files, the content is garbled and not the entire file is written out (reproducible with Small.vtk). Test data available here.
Thanks for opening an issue. I'll have a look.
I don't seem to have access to your example files EDIT: It seems to work now, thanks!