- Cloudrail 教程
- Cloudrail - 主页
- Cloudrail - 概览
- Cloudrail - Android
- Cloudrail - Java
- Cloudrail - Node.js
- Cloudrail - iOS
- Cloudrail - 社交登录
- Cloudrail - 设置
- Cloudrail - 编码
- Cloudrail 实用资源
- Cloudrail - 快速指南
- Cloudrail - 实用资源
- Cloudrail - 讨论
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"); }); });
广告