NodeJS SDK

The NodeJS SDK for electron or a node apps.

Installation

Download your SDK from Dev Portalarrow-up-right

Usage

Uploader

circle-info

Newfang uses a combination of your file's content hash and a convergence key to identify your file. The SDK exposes a method to generate this convergence key where you can specify:

App level convergence No duplication of any file across your app. Only a single copy of a specific file is stored. No need to call generate_convergence(). The SDK handles this. User level convergence No duplication of any file for a specific user. Different users can upload the same file and they would be treated as different copies. Call generate_convergence() once per user and store the convergence against a specific user. File level convergence All files are duplicated. The same user can upload the same file multiple times and they would be treated as separate copies. Call generate_convergence() each time you upload a file and store the convergence against that file.

const Uploader = require("/path/to/sdk/newfang_uploader").default;

// Generate convergence depending on the use case of your application
const convergence = Uploader.generate_convergence();

// Create an instance of the Uploader object and pass in the absolute path
// to your file and the convergence
const uploader = new Uploader({
    filePath: "/path/to/your/file",
    convergence
});

// Subscribe to the 'error' event and wrap it around your error handling
uploader.on("error", (e) => {
    console.log(e);
    // Error. Do something.
});

// Subscribe to the 'progress' event and inform your view
uploader.on("upload_progress", (percentage) => {
    console.log("upload progress: ", percentage + "%");
});

// Subscribe to the 'complete' event and wrap your completion handler code
// URI is the identifier for the uploaded file and the only way to access it
uploader.on("upload_complete", (uri) => {
    console.log({ uri });
    // Upload complete. Do something.
});

// Subscribe to all events before calling start
uploader.start_upload();

Downloader

Delete

Remember

  • Call the convergence once or multiple times depending on your apps use case.

  • Pass in the correct convergence in order to correctly upload/delete a file.

  • Start the operations(upload/download/delete) after subscribing to its events.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

None

Last updated

Was this helpful?