äºåå¨
uploadFileâ
1. æ¥å£æè¿°â
æ¥å£åè½ï¼ä¸ä¼ æä»¶
æ¥å£å£°æï¼
2.x çæ¬
uploadFile(options)
1.x çæ¬
uploadFile(localPath: string, cloudPath: string)
注æäºé¡¹: v2.x ä¸ v1.x ä¸å ¼å®¹
2. è¾å ¥åæ°â
| åæ®µ | å¿ å¡« | ç±»å | 说æ |
|---|---|---|---|
| localPath | æ¯ | String | æ¬å°æä»¶è·¯å¾ï¼å»ºè®®ä¼ å ¥ç»å¯¹è·¯å¾ |
| cloudPath | æ¯ | String | äºç«¯æä»¶è·¯å¾ï¼dir/data.txt |
| onProgress | æ¯ | Function | ä¸ä¼ è¿åº¦åè°å½æ° |
注ï¼å½ localPath 为æä»¶å¤¹æ¶ï¼SDK ä¼å°è¯å¨æ¤æä»¶å¤¹ä¸ï¼ä¸çº§ç®å½ï¼ä¸æ·±åº¦éåï¼å¯»æ¾å cloudPath 䏿å卿件ååçæä»¶ï¼å¦ cloudPath 为 dir/data.txtï¼åä¼å¯»æ¾ 'data.txt'ã
3. è¿åç»æâ
æ
4. 示ä¾ä»£ç â
import path from "path";
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // äºå¼åç¯å¢IDï¼å¯å¨è
¾è®¯äºäºå¼åæ§å¶å°è·å
});
async function test() {
await storage.uploadFile({
localPath: path.resolve("./data.txt"),
cloudPath: "files/data.txt",
onProgress: (data) => {},
});
}
test();
uploadDirectoryâ
1. æ¥å£æè¿°â
æ¥å£åè½ï¼ä¸ä¼ æä»¶å¤¹
æ¥å£å£°æï¼
2.x çæ¬
uploadDirectory(options)
1.x çæ¬
uploadDirectory(source: string, cloudPath: string)
注æäºé¡¹: v2.x ä¸ v1.x ä¸å ¼å®¹
æ¤æ¥å£ä¼éåç®æ æä»¶å¤¹ä¸ææçæä»¶å¹¶ä¸ä¼ ï¼åæ¶ä¿ææä»¶å¤¹ç»æã
2. è¾å ¥åæ°â
| åæ®µ | å¿ å¡« | ç±»å | 说æ |
|---|---|---|---|
| localPath | æ¯ | String | æ¬å°æä»¶å¤¹è·¯å¾ |
| cloudPath | æ¯ | String | äºç«¯æä»¶å¤¹è·¯å¾ |
| onProgress | æ¯ | Function | ä¸ä¼ è¿åº¦åè°å½æ° |
3. è¿åç»æâ
æ
4. 示ä¾ä»£ç â
import path from "path";
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // äºå¼åç¯å¢IDï¼å¯å¨è
¾è®¯äºäºå¼åæ§å¶å°è·å
});
async function test() {
await storage.uploadDirectory({
localPath: path.resolve("./files"),
cloudPath: "",
onProgress: (data) => {},
});
}
test();
downloadFileâ
1. æ¥å£æè¿°â
æ¥å£åè½ï¼ä¸è½½æä»¶
æ¥å£å£°æï¼
2.x çæ¬
downloadFile(options)
1.x çæ¬
downloadFile(cloudPath: string, localPath)
注æäºé¡¹: v2.x ä¸ v1.x ä¸å ¼å®¹
2. è¾å ¥åæ°â
| åæ®µ | å¿ å¡« | ç±»å | 说æ |
|---|---|---|---|
| cloudPath | æ¯ | String | äºç«¯æä»¶è·¯å¾ï¼dir/data.txt |
| localPath | æ¯ | String | æ¬å°æä»¶åå¨è·¯å¾ï¼æä»¶éæå®æä»¶åç§° |
3. è¿åç»æâ
æ (undefined)
4. 示ä¾ä»£ç â
import path from "path";
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // äºå¼åç¯å¢IDï¼å¯å¨è
¾è®¯äºäºå¼åæ§å¶å°è·å
});
async function test() {
await storage.downloadFile({
cloudPath: "files/data.txt",
localPath: path.resolve("./data.txt"),
});
}
test();
downloadDirectoryâ
1. æ¥å£æè¿°â
æ¥å£åè½ï¼ä¸è½½æä»¶å¤¹
æ¥å£å£°æï¼
2.x çæ¬
downloadDirectory(options)
1.x çæ¬
downloadDirectory(cloudPath: string, localPath: string)
注æäºé¡¹: v2.x ä¸ v1.x ä¸å ¼å®¹
2. è¾å ¥åæ°â
| åæ®µ | å¿ å¡« | ç±»å | 说æ |
|---|---|---|---|
| cloudPath | æ¯ | String | äºç«¯æä»¶å¤¹ |
| localPath | æ¯ | String | æ¬å°æä»¶åå¨è·¯å¾ï¼æä»¶éæå®æä»¶åç§° |
3. è¿åç»æâ
æ
4. 示ä¾ä»£ç â
import path from "path";
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // äºå¼åç¯å¢IDï¼å¯å¨è
¾è®¯äºäºå¼åæ§å¶å°è·å
});
async function test() {
await storage.downloadDirectory({
cloudPath: "files/music",
localPath: path.resolve("./music"),
});
}
test();
NOTEï¼
- æ¤æä½ä¼éåæä»¶å¤¹ä¸çæææä»¶ï¼å¦ææä»¶æ°éè¿å¤ï¼å¯è½ä¼é ææ§è¡å¤±è´¥ã
- å½ cloudPath ä¸å卿¶ï¼SDK ä¸ä¼ä¸è½½æä»¶ï¼ä¹ä¸ä¼æåºé误ã
listDirectoryFilesâ
1. æ¥å£æè¿°â
æ¥å£åè½ï¼ååºæä»¶å¤¹ä¸çæææä»¶
æ¥å£å£°æï¼listDirectoryFiles(cloudPath: string): Promise<IListFileInfo[]>
2. è¾å ¥åæ°â
| åæ®µ | å¿ å¡« | ç±»å | 说æ |
|---|---|---|---|
| cloudPath | æ¯ | String | äºç«¯æä»¶å¤¹è·¯å¾ï¼dir/data/ |
3. è¿åç»æâ
| åæ®µ | å¿ å¡« | ç±»å | 说æ |
|---|---|---|---|
| - | æ¯ | Array<FileItem> | æä»¶æ°ç» |
FileItemâ
| åæ®µ | ç±»å | 说æ |
|---|---|---|
| Key | String | å¯¹è±¡é® |
| LastModified | String | 对象æåä¿®æ¹æ¶é´ï¼ä¸º ISO8601 æ ¼å¼ï¼å¦ 2019-05-24T10:56:40Z date |
| ETag | String | 对象çå®ä½æ ç¾ï¼Entity Tagï¼ï¼æ¯å¯¹è±¡è¢«åå»ºæ¶æ è¯å¯¹è±¡å 容çä¿¡æ¯æ ç¾ï¼å¯ç¨äºæ£æ¥å¯¹è±¡çå 容æ¯å¦åçåå |
| Size | String | 对象大å°ï¼åä½ä¸º Byte |
| Owner | String | 对象ææè ä¿¡æ¯ |
| StorageClass | String | 对象åå¨ç±»åï¼æ ååå¨ STANDARD |
4. 示ä¾ä»£ç â
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // äºå¼åç¯å¢IDï¼å¯å¨è
¾è®¯äºäºå¼åæ§å¶å°è·å
});
async function test() {
const res1 = await storage.listDirectoryFiles("dir/data");
const res2 = await storage.listDirectoryFiles("dir/data", 20);
const res3 = await storage.listDirectoryFiles("dir/data", 20, "dir/dat");
for (let item in res1) {
console.log(item);
}
}
test();
getFileInfoâ
1. æ¥å£æè¿°â
æ¥å£åè½ï¼è·åæä»¶ä¿¡æ¯
æ¥å£å£°æï¼getFileInfo(cloudPath: string): Promise<IFileInfo>
2. è¾å ¥åæ°â
| åæ®µ | å¿ å¡« | ç±»å | 说æ |
|---|---|---|---|
| cloudPath | æ¯ | String | äºç«¯æä»¶è·¯å¾ dir/data.txt |