Skip to main content

Storage SDK

The Arcana JS SDK is a JavaScript SDK used to perform all file related operations for users of an application. These include:

  • Upload file
  • Download file
  • Delete file
  • Share file
  • Revoke file
  • Change owner

Files are uploaded using the tus protocol for resumable upload. This means that if an upload is interrupted for whatever reason either voluntarily (pausing the upload) or involuntarily (connection dropped), it will resume the upload from the point it last stopped.


Using npm/yarn#

npm i @arcana/storage
yarn add @arcana/storage

You can use the standalone module which includes the polyfills.

<script src="./dist/standalone/storage.umd.js"></script>

Using CDN#

<script src=""></script>
<script src=""></script>
import { Arcana } from '@arcana/storage/dist/standalone/storage.umd';


Create an Arcana instance#

// address: Smart contract address of app
// private key: Secp256K private key
// email: user's email ID
const arcanaInstance = new{appId, privateKey, email});


const Uploader = arcanaInstance.getUploader();
// file: Blob format


const Downloader = arcanaInstance.getDownloader();
// did: DID of file which you want to download;


const Access = new arcanaInstance.getAccess();

Share a file#

// did: DID of file to be shared
// publicKey: recipients public key
// validity: For how long will be the user able to download the file in seconds
Access.share([did], [publicKey], [validity]);

Revoke access#

// did: DID of file from which access is removed
// address: Address of the user who's access is getting revoked
Access.revoke(did, address);

Delete File#



//Get consumed and total storage of the current user
let [consumed, total] = await Access.getUploadLimit();
//Get consumed and total bandwidth of the current user
let [consumed, total] = await Access.getDownloadLimit();

File shared with current user#

let files = await arcanaInstance.sharedFiles();

List of files uploaded by the user#

let files = await arcanaInstance.myFiles();

FallBack Functions#

1. Upload#

1.1 On Success#
uploader.onSuccess = () => {
console.log('Completed file upload');
1.2 On Error#
uploader.onError = (err) => {
console.log('Error', err);
1.3 On Progress#
uploader.onProgress = (bytesUploaded: number, bytesTotal: number) => {
console.log("Completed", bytesUploaded, "out of", bytesTotal)

2. Download#

2.1 On Success#
downloader.onSuccess = () => {
console.log('Completed file download');
2.2 On Progress#
downloader.onProgress = (bytesDownloaded: number, bytesTotal: number) => {
console.log("Completed", bytesDownloaded, "out of", bytesTotal)

Error List#

UNAUTHORIZEDYou can't download this fileTrying to download a file which is neither owned by you nor shared with you
TRANSACTION*Smart contract Errors
TRANSACTIONNo space left for userYou have already consumed your storage or bandwidht limit