Cloudrail - Node.js


本节介绍如何使用CloudRail的Node.js SDK。

设置

最简单的安装方法是通过NPM。只需使用以下命令 -

npm install cloudrail-si

用法

以下示例演示如何创建新文件夹并将文件从本地计算机上传到任何云存储提供商上新创建的文件夹。

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

// let cs = new cloudrail.services.Box(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
// let cs = new cloudrail.services.OneDrive(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
// let cs = new cloudrail.services.GoogleDrive(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
let cs = new cloudrail.services.Dropbox(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[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");
   });
});