cozy / cozy-browser-sdk

Cozy Data System client for the browser
http://dev.cozy.io
MIT License
7 stars 12 forks source link

Allow to add a binary / attachment #14

Open aenario opened 8 years ago

aenario commented 8 years ago

We need to find a proper API, I offer :

Option 1 - mikeal/request like, where we return the xhr object, so the app can setup its listeners

file = document.getElementbyId('input_file').files[0]
request = cozysdk.attachBinary 'Note', 454id543, 'binary_name.ext', file, callback
request.addEventListener("abort", transferCanceled);
request.upload.addEventListener("progress", updateProgress);
request.upload.addEventListener("abort", transferCanceled);

Option 2 - with a progressback

file = document.getElementbyId('input_file').files[0]
progressback = (event) -> event instanceof ProgressEvent
cozysdk.attachBinary 'Note', 454id543, 'binary_name.ext', file, callback, progressback

*1 event is a ProgressEvent

Option 3 - only provide the url, and some doc on how to use it with <form>