The methods below allow you to upload and download files. These files are encrypted before upload and decrypted after download.

Note

This documentation uses flow type annotations.

Upload

Encrypt and upload a file.

type FileId = string;
type Data = ArrayBuffer | Buffer | Blob | File | Uint8Array;
type UploadOptions = { shareWithUsers?: Array<string>, onProgress?: Function };

function upload(clearData: Data, options?: UploadOptions): Promise<FileId>
Parameters Description
clearData: Data The data of the file to upload
options: UploadOptions Object defining the upload options
Returns
Promise The fileId of the uploaded file
Throws Description
InvalidArgument Some recipients have not been found, or clearData is not a valid input
PreconditionFailed FileKit session has not been started
NetworkError Network error, e.g. connection lost or the Tanker server is not reachable

UploadOptions

The shareWithUsers option allows you to specify who will be able to decrypt a file. If none is provided, only the user who uploaded the file will be able to decrypt it.

Fields Default Description
shareWithUsers: Array<string> [] The user public identities to share with (the current user's identity will be automatically appended)
onProgress: Function (none) A handler function to track progress. It will be called several times with a single argument in the following format:
{ currentBytes: number, totalBytes: number }

Download

Download and decrypt a file.

type DownloadOptions = { onProgress?: Function };

function download(fileId: FileId, options?: DownloadOptions): Promise<File>
Parameters Description
fileId: string The fileId of the file to download
options: DownloadOptions Object defining the download options
Returns
Promise<File> The decrypted data in the File format
Throws Description
InvalidArgument The fileId provided does not match with any file uploaded on FileKit
PreconditionFailed FileKit session has not been started
NetworkError Network error, e.g. connection lost or the Tanker server is not reachable

DownloadToDisk

Download, decrypt and save a file to disk.

function downloadToDisk(fileId: FileId, options?: DownloadOptions): Promise<void>
Parameters Description
fileId: string The fileId of the file to download
options: DownloadOptions Object defining the download options
Returns
Promise The promise is fulfilled once the download operation is done
Throws Description
InvalidArgument The fileId provided does not match with any file uploaded on FileKit
PreconditionFailed FileKit session has not been started
NetworkError Network error, e.g. connection lost or the Tanker server is not reachable

DownloadOptions

Fields Default Description
onProgress: Function (none) A handler function to track progress. It will be called several times with a single argument in the following format:
{ currentBytes: number, totalBytes: number }