English 中文(简体)
Cloudrail - Node.js
  • 时间:2024-12-22

Cloudrail - Node.js


Previous Page Next Page  

This section gives an introduction on how to use CloudRail s Node.js SDK.

Setup

The easiest way to install is via NPM. Simply use the following command −

npm install cloudrail-si

Usage

The following example shows how to create a new folder and upload a file from the local machine to the newly created folder on any cloud storage provider.

javascript
const cloudrail = require("cloudrail-si");
cloudrail.Settings.setKey("[CloudRail License Key]");

// let cs = new cloudrail.services.Box(redirectReceiver, "[cpentIdentifier]", "[cpentSecret]", "[redirectUri]", "[state]");
// let cs = new cloudrail.services.OneDrive(redirectReceiver, "[cpentIdentifier]", "[cpentSecret]", "[redirectUri]", "[state]");
// let cs = new cloudrail.services.GoogleDrive(redirectReceiver, "[cpentIdentifier]", "[cpentSecret]", "[redirectUri]", "[state]");
let cs = new cloudrail.services.Dropbox(redirectReceiver, "[cpentIdentifier]", "[cpentSecret]", "[redirectUri]", "[state]");

cs.createFolder("/TestFolder", (err) => { // <---
   if (err) throw err;
   let fileStream = fs.createReadStream("UserData.csv");
   let size = fs.statSync("UserData.csv").size;
   
   cs.upload("/TestFolder/Data.csv", fileStream, size, false, (err) => { // <---
      if (err) throw err;
      console.log("Upload successfully finished");
   });
});
Advertisements