binaries

cozysdk functions to manipulate document binaries

Binaries can be attached to a document. Attaching binaries is not supported in cozysdk for browser, if your application needs to create document with binaries, add +1 to the Github ticket related to this feature.

Methods

(static) addBinary(docType, id, file, nameopt, callbackopt)

Create a binary linked to the document matching ID. Several binaries can be attached to a document, so a name is required to distinguish them.
Parameters:
Name Type Attributes Description
docType string The docType of the document to add a binary from.
id string The id of the document to add a binary from.
file object An object containing either the binary to create or an URL.
name string <optional>
The name of the binary attached. (filename by default)
callback callback <optional>
A node.js style callback
Examples

fromURL

cozysdk.addBinary('File', 524fileid452, { fromURL: 'http://...' }, 'file')

fromBinary

cozysdk.addBinary('File', 524fileid452, { fromBinary: blob }, 'file')

(static) getBinaryURL(docType, id, name, callbackopt)

Build file url for file linked to the document matching ID. Several binaries can be attached to a document, so a name is required to know which file should be retrieved. It's useful when you want to retrieve a file from the file application or a picture from the photo app.
Parameters:
Name Type Attributes Description
docType string The docType of the document to retrieve a binary from.
id string The id of the document to retrieve a binary from.
name string The name of the binary to retrieve.
callback callback <optional>
A node.js style callback
Examples

callback

cozysdk.getBinaryURL('Note', '524noteid452', 'image.jpg', function(err, url){
    img.src = url
    // url = 'https://your.cozy.cloud/ds-api/524noteid542/binaries/...
    //                                ...image.jpg?=token=zdkgzerozernxwxoicvh'
});

promise

cozysdk.getBinaryURL('Note', '524noteid452', 'image.jpg')

(static) removeBinary(docType, id, name, callbackopt)

Delete binary linked to the document matching ID. Several binaries can be attached to a document, so a name is required to know which file should be deleted.
Parameters:
Name Type Attributes Description
docType string The docType of the document to remove a binary from.
id string The id of the document to remove a binary from.
name string The name of the binary to destroy.
callback callback <optional>
A node.js style callback
Examples

callback

cozysdk.removeBinary('Note', '524noteid452', 'image.jpg', function(err){
    // image.jpg has been removed from note 524noteid452
});

promise

cozysdk.removeBinary('Note', '524noteid452', 'image.jpg')