xeus-python icon indicating copy to clipboard operation
xeus-python copied to clipboard

FileUpload widget received data is corrupted

Open lassoan opened this issue 5 years ago • 2 comments

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.

lassoan avatar May 06 '20 18:05 lassoan

Thanks for opening an issue. I'll have a look.

martinRenou avatar May 07 '20 06:05 martinRenou

I don't seem to have access to your example files EDIT: It seems to work now, thanks!

martinRenou avatar May 07 '20 07:05 martinRenou