peteut / ipython-file-upload

IPython file upload widget. Now obsolete, refer to widgets.https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html#File-Upload
33 stars 11 forks source link

Support for binary file transfer in ipywidgets 7 #20

Open jasongrout opened 7 years ago

jasongrout commented 7 years ago

In ipywidgets 7.0, attributes can be binary and will then be synced with binary messages. That may make a big difference for large files (instead of base64 encoding them).

Also, FYI, @draperjames was looking into making a standard file upload widget in the base ipywidgets package (https://github.com/jupyter-widgets/ipywidgets/issues/1542). Would you be willing to collaborate on such a standard widget?

Thanks for writing this!

peteut commented 7 years ago

+1 for a standard widget, that would be nice! Binary upload should be easy to support, as there is FileReader#readAsBinaryString.

peteut commented 7 years ago

@jasongrout I just realised that FileReader#readAsBinaryString is non-standard: Note that this method is now deprecated as per the 12 July 2012 Working Draft from the W3C.

jasongrout commented 7 years ago

You'll want to use https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsArrayBuffer - ArrayBuffers are what ipywidgets recognizes as a binary state value.

draperjames commented 7 years ago

@jasongrout looks like a winner to me. It even works on Edge. The only thing is the status is listed as working draft should we expect drastic changes in the future or will it stay more or less as is?

jasongrout commented 7 years ago

Good question. We can update the code if it does change.

jasongrout commented 7 years ago

But it seems to have been implemented for years - it sounds pretty safe.

hugulas commented 5 years ago

@peteut I modified the code to support binary file. And I plan to contribute the patch back. Would you mind to review the patch?If yes, I will need to go through my company's open source process first. Thanks.