Cloud storage
uploadFile
1. API Description
API feature: upload files
API Declaration:
2.x version
uploadFile(options)
1.x version
uploadFile(localPath: string, cloudPath: string)
Note: v2.x is incompatible with v1.x.
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| localPath | Yes | String | Local file path. It is recommended to pass an absolute path. |
| cloudPath | Required | String | Cloud file path: dir/data.txt |
| onProgress | Required | Function | Upload progress callback function |
Note: When localPath is a folder, the SDK will attempt to find a file with the same name as the file in cloudPath within this folder (first-level directory, no deep traversal). For example, if cloudPath is dir/data.txt, it will look for 'data.txt'.
3. Return Results
N/A
4. Sample Code
import path from "path";
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
await storage.uploadFile({
localPath: path.resolve("./data.txt"),
cloudPath: "files/data.txt",
onProgress: (data) => {},
});
}
test();
uploadDirectory
1. API Description
API feature: Uploading folders
API Declaration:
2.x version
uploadDirectory(options)
1.x version
uploadDirectory(source: string, cloudPath: string)
Note: v2.x is incompatible with v1.x.
This API traverses all files in the target folder and uploads them while preserving the folder structure.
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| localPath | Required | String | Local folder path |
| cloudPath | Required | String | Cloud folder path |
| onProgress | Required | Function | Upload progress callback function |
3. Return Results
N/A
4. Sample Code
import path from "path";
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
await storage.uploadDirectory({
localPath: path.resolve("./files"),
cloudPath: "",
onProgress: (data) => {},
});
}
test();
downloadFile
1. API Description
API feature: download files
API Declaration:
2.x version
downloadFile(options)
1.x version
downloadFile(cloudPath: string, localPath)
Note: v2.x is incompatible with v1.x.
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| cloudPath | Required | String | Cloud file path: dir/data.txt |
| localPath | Required | String | Local file storage path; the file name must be specified |
3. Return Results
None (undefined)
4. Sample Code
import path from "path";
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
await storage.downloadFile({
cloudPath: "files/data.txt",
localPath: path.resolve("./data.txt"),
});
}
test();
downloadDirectory
1. API Description
API feature: download folder
API Declaration:
2.x version
downloadDirectory(options)
1.x version
downloadDirectory(cloudPath: string, localPath: string)
Note: v2.x is incompatible with v1.x.
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| cloudPath | Required | String | Cloud folder |
| localPath | Required | String | Local file storage path; the file name must be specified |
3. Return Results
N/A
4. Sample Code
import path from "path";
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
await storage.downloadDirectory({
cloudPath: "files/music",
localPath: path.resolve("./music"),
});
}
test();
NOTE:
- This operation traverses all files in the folder. If the number of files is too large, it may cause the execution to fail.
- When cloudPath does not exist, the SDK will not download the file and will not throw an error.
listDirectoryFiles
1. API Description
API feature: List all files in the folder
API declaration: listDirectoryFiles(cloudPath: string): Promise<IListFileInfo[]>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| cloudPath | Required | String | Cloud folder path: dir/data/ |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| - | Required | Array<FileItem> | File array |
FileItem
| Field | Type | Description |
|---|---|---|
| Key | String | Object Key |
| LastModified | String | Last modified time of the object, in ISO8601 format, such as 2019-05-24T10:56:40Z date |
| ETag | String | The entity tag (Entity Tag) of the object, which is an information tag that identifies the content of the object when it is created and can be used to check whether the content of the object has changed |
| Size | String | Object size, unit: bytes |
| Owner | String | Object owner information |
| StorageClass | String | COS storage type: Standard Storage STANDARD |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
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. API Description
API feature: Obtain file information
API declaration: getFileInfo(cloudPath: string): Promise<IFileInfo>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| cloudPath | Required | String | Cloud file path dir/data.txt |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| Size | Required | String | File size, unit: KB |
| Type | Required | String | File type |
| Date | Required | String | Modification time |
| ETag | Yes | String | Entity tag of the object (Entity Tag) |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const info = await storage.getFileInfo("files/data.txt");
console.log(info);
}
test();
deleteFile
1. API Description
API feature: Batch delete files
API declaration: deleteFile(cloudPathList: string[])
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| cloudPathList | Required | Array<String> | String array consisting of cloud file paths ['dir/data.txt'] |
3. Return Results
N/A
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
await storage.deleteFile(["files/data.txt"]);
}
test();
deleteDirectory
1. API Description
API feature: Delete a folder
API declaration: deleteDirectory(cloudPath: string)
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| cloudPath | Required | String | Cloud folder path |
Note: When cloudPath does not exist, the SDK will not throw an error.
3. Return Results
N/A
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
await storage.deleteDirectory("files/");
}
test();
getTemporaryUrl
1. API Description
API feature: Obtain a temporary download link for a file
API declaration: getTemporaryUrl(fileList: (string | TempUrlInfo)[]):Promise<Array.<FileUrlItem>>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| fileList | Required | String or Array.<TempUrlInfo> | Array of cloud file paths or Array of TempUrlInfo |
TempUrlInfo
| Field | Required | Type | Description |
|---|---|---|---|
| cloudPath | Required | String | Cloud file path |
| maxAge | Required | Number | Validity period of the temporary download link, unit: seconds |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| - | Required | Array.<FileUrlItem> | List of file download URLs |
FileUrlItem
| Field | Required | Type | Description |
|---|---|---|---|
| fileId | Required | String | File Id |
| url | Required | String | download link |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const urls = await storage.getTemporaryUrl(["files/data.txt"]);
const urls2 = await storage.getTemporaryUrl([
{
cloudPath: "files/data.txt",
maxAge: 86400,
},
]);
for (let item in urls) {
console.log(item.url);
}
}
test();
getStorageAcl
1. API Description
API feature: Obtain file storage permissions
API declaration: getStorageAcl(): Promise<string>
2. Input Parameters
Empty
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| - | Required | String | Permission type |
All permission types:
- READONLY: Readable by all users, writable only by the creator and administrators.
- PRIVATE: Readable and writable only by the creator and administrators.
- ADMINWRITE: Readable by all users, writable only by administrators.
- ADMINONLY: Readable and writable only by administrators
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const acl = await storage.getStorageAcl();
console.log(acl);
}
test();
setStorageAcl
1. API Description
API feature: Set file storage permissions
API declaration: setStorageAcl(acl: string):Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| acl | Yes | String | File storage permission description |
Supported options for acl:
- READONLY: Readable by all users, writable only by the creator and administrators.
- PRIVATE: Readable and writable only by the creator and administrators.
- ADMINWRITE: Readable by all users, writable only by administrators.
- ADMINONLY: Readable and writable only by administrators
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { storage } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
await storage.setStorageAcl("READONLY");
}
test();
listCurrentDirectory
1. API Description
API feature: List files and subdirectories in the specified directory (non-recursive, current level only)
API declaration: app.storage.listCurrentDirectory(dirPath?: string): Promise<Object>
This API has been supported since v5.0.0.
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| dirPath | Optional | String | Cloud directory path. If not provided, the root directory is listed; no trailing / required. |
3. Return Results
| Field | Type | Description |
|---|---|---|
| files | IListFileInfo[] | File list at the current level |
| directories | String[] | List of subdirectory names at the current level |
4. Sample Code
const CloudBase = require('@cloudbase/manager-node')
const app = new CloudBase({ secretId: 'Your SecretId', secretKey: 'Your SecretKey', envId: 'your-env-id' })
async function test() {
const { files, directories } = await app.storage.listCurrentDirectory('images')
console.log('File:', files)
console.log('Subdirectory:', directories)
}
test()
copyFile
1. API Description
API feature: copies a single cloud file to a new path
API declaration: app.storage.copyFile(options: ICopyOptions): Promise<ICopyResult>
This API has been supported since v5.0.0.
2. Input Parameters
ICopyOptions
| Field | Required | Type | Description |
|---|---|---|---|
| sourcePath | Required | String | Source file cloud path, for example images/a.jpg |
| destPath | Required | String | Target file cloud path, for example backup/a.jpg |
| force | No | Boolean | whether to forcibly overwrite existing target files, defaults to false |
| skipExisting | No | Boolean | Skip if target already exists (without error), default false |
3. Return Results
ICopyResult
| Field | Type | Description |
|---|---|---|
| success | Boolean | whether the operation was successful |
| sourcePath | String | Source path |
| destPath | String | Target path |
| size | Number | File size (bytes) |
| status | String | Status: copied / skipped / failed |
| error | String | Error message when the operation fails |
4. Sample Code
async function test() {
const result = await app.storage.copyFile({
sourcePath: 'images/logo.png',
destPath: 'backup/logo.png',
force: true
})
console.log('Copy result:', result)
}
test()
copyDirectory
1. API Description
API feature: recursively copies cloud directories to a new path, supports glob filtering and concurrency control
API declaration: app.storage.copyDirectory(options: ICopyDirectoryOptions): Promise<ICopyResult[]>
This API has been supported since v5.0.0.
2. Input Parameters
ICopyDirectoryOptions (extends ICopyOptions)
| Field | Required | Type | Description |
|---|---|---|---|
| sourcePath | Required | String | Cloud path of the source directory |
| destPath | Required | String | Cloud path of the target directory |
| force | No | Boolean | whether to forcibly overwrite existing files, defaults to false |
| skipExisting | No | Boolean | Skip if target already exists, default false |
| include | No | String | String[] | Include pattern (glob format) |
| exclude | No | String | String[] | Exclude pattern (glob format) |
| parallel | No | Number | Concurrency, default 20 |
| onProgress | No | Function | Progress callback (info: ICopyProgress) => void |
ICopyProgress
| Field | Type | Description |
|---|---|---|
| copied | Number | Copied count |
| skipped | Number | Skipped count |
| total | Number | Total file count |
| currentFile | String | File being processed |
3. Return Results
Promise<ICopyResult[]> — An array of copy results for each file, with the same structure as the return value of copyFile.
4. Sample Code
async function test() {
const results = await app.storage.copyDirectory({
sourcePath: 'src-dir/',
destPath: 'dest-dir/',
include: ['**/*.jpg', '**/*.png'],
force: true,
onProgress: ({ copied, total }) => console.log(`${copied}/${total}`)
})
console.log('Directory copy completed, total:', results.length, 'files')
}
test()
moveFile
1. API Description
API feature: moves a single cloud file to a new path (copies and then deletes the source file)
API declaration: app.storage.moveFile(options: ICopyOptions): Promise<ICopyResult>
This API has been supported since v5.0.0.
2. Input Parameters
Same as copyFile, with exactly the same parameter structure.
ICopyOptions
| Field | Required | Type | Description |
|---|---|---|---|
| sourcePath | Required | String | Cloud path of the source file |
| destPath | Required | String | Cloud path of the target file |
| force | No | Boolean | whether to forcibly overwrite existing target files, defaults to false |
| skipExisting | No | Boolean | Skip if target already exists, default false |
3. Return Results
Same as copyFile, returns ICopyResult.
4. Sample Code
async function test() {
const result = await app.storage.moveFile({
sourcePath: 'temp/upload.jpg',
destPath: 'images/upload.jpg',
force: true
})
console.log('Move result:', result.status)
}
test()
moveDirectory
1. API Description
API feature: recursively move a cloud directory to a new path (copy and then delete the source directory)
API declaration: app.storage.moveDirectory(options: ICopyDirectoryOptions): Promise<ICopyResult[]>
This API has been supported since v5.0.0.
2. Input Parameters
Same as copyDirectory, with exactly the same parameter structure.
3. Return Results
Same as copyDirectory, returns ICopyResult[].
4. Sample Code
async function test() {
const results = await app.storage.moveDirectory({
sourcePath: 'old-dir/',
destPath: 'new-dir/',
force: true
})
console.log('Directory move completed, total:', results.length, 'files')
}
test()
searchFiles
1. API Description
API feature: Search for files in a specified directory using a glob pattern or regular expression.
API declaration: app.storage.searchFiles(options: ISearchOptions): Promise<ISearchResult[]>
This API has been supported since v5.0.0.
2. Input Parameters
ISearchOptions
| Field | Required | Type | Description |
|---|---|---|---|
| pattern | Required | String | Search pattern, supporting glob or regular expression strings |
| path | Optional | String | Search directory path. If not specified, the root directory is searched. |
| isRegex | No | Boolean | When true, parses pattern as a regular expression; default false |
| fileType | Optional | String | File type filtering, e.g., jpg, png |
| limit | Optional | Number | Maximum number of results to return, default 100 |
| includeDetails | No | Boolean | whether to include file size and modification time, default false |
3. Return Results
ISearchResult[]
| Field | Type | Description |
|---|---|---|
| key | String | Cloud file path |
| type | String | Type: file / directory |
| size | Number | File size (bytes), only valid for files |
| lastModified | String | Last modified time (in ISO format), only valid for files |
4. Sample Code
async function test() {
const results = await app.storage.searchFiles({
pattern: '**/*.jpg',
path: 'images',
limit: 50,
includeDetails: true
})
results.forEach(f => console.log(f.key, f.size))
}
test()
PostgreSQL Environment
The following APIs target CloudBase environments using the PostgreSQL architecture, and are implemented on top of the CloudBase Storage HTTP API. They are available since @cloudbase/manager-node@5.4.0.
-
These APIs target a different architecture from the COS-SDK based ones above (
uploadFile/downloadFile/listDirectoryFiles, etc.) and must not be mixed. -
Every API requires an
accessToken(Bearer Token). It can be one of:access_token: end-user login tokenapiKey: server-side admin token (a long-lived JWT, created byenv.createApiKey)publishableKey: anonymous frontend token
⚠️
apiKeyMUST NEVER be used on the client side. -
Every API accepts an optional
envIdfield that overrides the current environment ID; if omitted, theenvIdprovided when initializing the manager is used.
Common Error Shape
When a PG Storage HTTP API call fails, a CloudBaseError is thrown with the following fields:
| Field | Description |
|---|---|
message | Description in the form <code>: <message> |
code | The server-returned Code; falls back to HTTP_<status> if not parseable |
requestId | Server-returned RequestId (useful for support tickets) |
uploadObject
1. Description
Uploads an object via the HTTP API as a binary stream.
Signature: app.storage.uploadObject(options): Promise<IUploadObjectHttpResult>
2. Input Parameters
IUploadObjectHttpOptions
| Field | Required | Type | Description |
|---|---|---|---|
| bucketId | Yes | String | Bucket ID |
| objectName | Yes | String | Object name; supports paths, e.g. folder/file.png |
| localPath | No | String | Absolute or relative path to a local file (use either this or body) |
| body | No | Buffer / NodeJS.ReadableStream | File content (use either this or localPath) |
| contentType | No | String | MIME type; if omitted, inferred in order of extension → magic bytes |
| contentLength | No | Number | File size in bytes; auto-inferred from localPath or Buffer if omitted |
| cacheControl | No | Number / String | A number is converted to max-age=<value>; a string is used as the Cache-Control header verbatim |
| metadata | No | Object | Custom metadata; will be Base64(JSON) encoded into the X-Metadata header |
| xRobotsTag | No | String | X-Robots-Tag header |
| upsert | No | Boolean | When using POST, allows overwriting (x-upsert: true); defaults to false |
| usePut | No | Boolean | Use the PUT method, equivalent to forcing overwrite; defaults to false |
| accessToken | Yes | String | Bearer Token |
| envId | No | String | Overrides the current envId |
Constraint: maximum single-file size is 100 MB; exceeding it throws FileSizeLimitExceeded.
3. Return Result
IUploadObjectHttpResult
| Field | Type | Description |
|---|---|---|
| Id | String | Object ID |
| Key | String | Object Key (including path) |
4. Sample Code
const res = await app.storage.uploadObject({
bucketId: 'my-bucket',
objectName: 'images/avatar.png',
localPath: './avatar.png',
cacheControl: 3600,
metadata: { source: 'manager-node' },
upsert: true,
accessToken: '<your-access-token>'
})
console.log(res.Id, res.Key)
deleteObject
1. Description
Deletes a single object.
Signature: app.storage.deleteObject(options): Promise<IDeleteObjectHttpResult>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| bucketId | Yes | String | Bucket ID |
| objectName | Yes | String | Object name |
| accessToken | Yes | String | Bearer Token |
| envId | No | String | Overrides the current envId |
3. Return Result
| Field | Type | Description |
|---|---|---|
| message | String | Gateway message, e.g. Successfully deleted |
deleteObjects
1. Description
Deletes objects in batch; up to 20 objects per call.
Signature: app.storage.deleteObjects(options): Promise<IDeletedObjectInfo[]>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| bucketId | Yes | String | Bucket ID |
| prefixes | Yes | String[] | List of object names to delete, 1 to 20. Despite the field name prefixes, items are matched as full object names (exact match), NOT as prefixes. |
| accessToken | Yes | String | Bearer Token |
| envId | No | String | Overrides the current envId |
3. Return Result
IDeletedObjectInfo[]. Each item contains fields like name / bucket_id / owner_id. Non-existent objects are silently skipped by the server (they don't appear in the returned array).
4. Sample Code
const deleted = await app.storage.deleteObjects({
bucketId: 'my-bucket',
prefixes: ['test/a.txt', 'test/b.txt'],
accessToken: '<your-access-token>'
})
console.log(deleted.map(d => d.name))
copyObject
1. Description
Copies an object.
Signature: app.storage.copyObject(options): Promise<ICopyObjectHttpResult>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| bucketId | Yes | String | Source bucket ID |
| sourceKey | Yes | String | Source object name |
| destinationKey | Yes | String | Destination object name |
| destinationBucket | No | String | Destination bucket ID; defaults to the source bucket |
| metadata | No | Object | System metadata; takes effect only when copyMetadata=false, merged with the source metadata. COS only recognizes cacheControl / mimetype / contentType |
| userMetadata | No | Object | User custom metadata; takes effect only when copyMetadata=false and fully replaces the destination user_metadata (passed via x-metadata Base64(JSON) header) |
| copyMetadata | No | Boolean | Whether to copy the source object's metadata; defaults to true. When true, metadata / userMetadata are ignored |
| upsert | No | Boolean | Allow overwriting an existing object at the destination |
| accessToken | Yes | String | Bearer Token |
| envId | No | String | Overrides the current envId |
3. Return Result
ICopyObjectHttpResult: contains Id / Key / name / bucket_id / owner_id / version / created_at / updated_at / last_accessed_at / metadata / user_metadata, etc.
moveObject
1. Description
Moves an object; the server performs copy + delete source atomically.
Signature: app.storage.moveObject(options): Promise<IMoveObjectHttpResult>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| bucketId | Yes | String | Source bucket ID |
| sourceKey | Yes | String | Source object name |
| destinationKey | Yes | String | Destination object name |
| destinationBucket | No | String | Destination bucket ID; defaults to the source bucket |
| accessToken | Yes | String | Bearer Token |
| envId | No | String | Overrides the current envId |
3. Return Result
| Field | Type | Description |
|---|---|---|
| message | String | Server message, e.g. Successfully moved |
| Id | String | Destination object ID |
| Key | String | Destination object Key |
listObjects
1. Description
Lists objects under a bucket; supports prefix filtering, pagination and sorting.
Signature: app.storage.listObjects(options): Promise<IListObjectsHttpResult>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| bucketId | Yes | String | Bucket ID |
| prefix | No | String | Path prefix |
| limit | No | Number | Page size, 1-1000 |
| cursor | No | String | Pagination cursor (the previous response's nextCursor) |
| withDelimiter | No | Boolean | Whether to use / as the folder delimiter |
| sortBy | No | Object | { column?: 'name' | 'created_at' | 'updated_at', order?: 'asc' | 'desc' } |
| accessToken | Yes | String | Bearer Token |
| envId | No | String | Overrides the current envId |
3. Return Result
IListObjectsHttpResult
| Field | Type | Description |
|---|---|---|
| folders | IListObjectsFolderItem[] | Folder entries |
| objects | IListObjectsObjectItem[] | Object entries (with name / id / metadata / created_at / updated_at, etc.) |
| hasNext | Boolean | Whether there is a next page |
| nextCursor | String | Cursor for the next page |
| nextCursorKey | String | Key for the next-page cursor |
signObject
1. Description
Generates a signed download URL for a single object.
Signature: app.storage.signObject(options): Promise<ISignObjectHttpResult>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| bucketId | Yes | String | Bucket ID |
| objectName | Yes | String | Object name |
| expiresIn | Yes | Number | Expiration in seconds; >= 1 |
| accessToken | Yes | String | Bearer Token |
| envId | No | String | Overrides the current envId |
3. Return Result
| Field | Type | Description |
|---|---|---|
| signedURL | String | Signed download URL |
signObjects
1. Description
Generates signed download URLs for multiple objects in batch; up to 500 objects per call.
Signature: app.storage.signObjects(options): Promise<ISignObjectsHttpResult>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| bucketId | Yes | String | Bucket ID |
| paths | Yes | String[] | List of object names, 1-500 |
| expiresIn | Yes | Number | Expiration in seconds; >= 1 |
| accessToken | Yes | String | Bearer Token |
| envId | No | String | Overrides the current envId |
3. Return Result
ISignedObjectItem[]
| Field | Type | Description |
|---|---|---|
| path | String | Object name |
| signedURL | String / null | Signed URL; null on failure |
| error | String / null | Per-item error message; null on success |
signUploadObject
1. Description
Generates a signed upload URL for an object.
Signature: app.storage.signUploadObject(options): Promise<ISignUploadObjectHttpResult>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| bucketId | Yes | String | Bucket ID |
| objectName | Yes | String | Object name |
| upsert | No | Boolean | When true, allows overwrite (x-upsert: true); defaults to false |
| accessToken | Yes | String | Bearer Token |
| envId | No | String | Overrides the current envId |
3. Return Result
| Field | Type | Description |
|---|---|---|
| url | String | Signed upload URL |
| token | String | Signature token; used together with uploadObjectBySign |
uploadObjectBySign
1. Description
Uploads an object using a signed URL; does NOT require the Authorization header.
Signature: app.storage.uploadObjectBySign(options): Promise<IUploadObjectBySignHttpResult>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| bucketId | Yes | String | Bucket ID |
| objectName | Yes | String | Object name |
| token | Yes | String | The signature token returned by signUploadObject |
| localPath | No | String | Local file path (use either this or body) |
| body | No | Buffer / NodeJS.ReadableStream | File content |
| contentType | No | String | If omitted, inferred from extension → magic bytes |
| contentLength | No | Number | Auto-inferred when omitted |
| envId | No | String | Overrides the current envId |
3. Return Result
| Field | Type | Description |
|---|---|---|
| Key | String | The object Key after a successful upload |
downloadAuthenticatedObject
1. Description
Downloads an authenticated object; always sends the Authorization header.
Signature: app.storage.downloadAuthenticatedObject(options): Promise<IDownloadObjectHttpResult>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| bucketId | Yes | String | Bucket ID |
| objectName | Yes | String | Object name |
| accessToken | Yes | String | Bearer Token |
| method | No | 'GET' / 'HEAD' | HTTP method; defaults to GET |
| download | No | String | Triggers a browser download; the value is used as the download filename |
| ifNoneMatch | No | String | If-None-Match header |
| ifModifiedSince | No | String | If-Modified-Since header |
| range | No | String | Range header (resumable downloads) |
| envId | No | String | Overrides the current envId |
3. Return Result
IDownloadObjectHttpResult
| Field | Type | Description |
|---|---|---|
| status | Number | HTTP status code (200 / 206 / 304, etc.) |
| headers | Object | Response headers (lowercase keys) |
| body | NodeJS.ReadableStream / null | Readable stream for GET; null for HEAD |
4. Sample Code
import fs from 'fs'
const { status, body } = await app.storage.downloadAuthenticatedObject({
bucketId: 'my-bucket',
objectName: 'images/avatar.png',
accessToken: '<your-access-token>'
})
if (body) body.pipe(fs.createWriteStream('./avatar.png'))
downloadObject
1. Description
Downloads an object; accessToken is optional. When omitted, only public buckets are accessible.
Signature: app.storage.downloadObject(options): Promise<IDownloadObjectHttpResult>
2. Input Parameters
Same as downloadAuthenticatedObject, except that accessToken is optional.
3. Return Result
Same as downloadAuthenticatedObject.
downloadPublicObject
1. Description
Downloads a public object; no authentication required. The target must be a public bucket.
Signature: app.storage.downloadPublicObject(options): Promise<IDownloadObjectHttpResult>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| bucketId | Yes | String | Bucket ID (must be a public bucket) |
| objectName | Yes | String | Object name |
| method | No | 'GET' / 'HEAD' | Defaults to GET |
| download | No | String | Triggers a browser download |
| envId | No | String | Overrides the current envId |
3. Return Result
Same as downloadAuthenticatedObject.
downloadObjectBySign
1. Description
Downloads an object using a signed URL; does not require the Authorization header.
Signature: app.storage.downloadObjectBySign(options): Promise<IDownloadObjectHttpResult>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| bucketId | Yes | String | Bucket ID |
| objectName | Yes | String | Object name |
| token | Yes | String | Signature token (extracted from the URL returned by signObject / signObjects, or held by the caller) |
| method | No | 'GET' / 'HEAD' | Defaults to GET |
| download | No | String | Triggers a browser download |
| envId | No | String | Overrides the current envId |
3. Return Result
Same as downloadAuthenticatedObject.
getObjectInfoAuthenticated
1. Description
Gets object metadata (authenticated).
Signature: app.storage.getObjectInfoAuthenticated(options): Promise<IGetObjectInfoHttpResult>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| bucketId | Yes | String | Bucket ID |
| objectName | Yes | String | Object name |
| method | No | 'GET' / 'HEAD' | GET returns JSON; HEAD returns only response headers |
| accessToken | Yes | String | Bearer Token |
| envId | No | String | Overrides the current envId |
3. Return Result
IGetObjectInfoHttpResult
| Field | Type | Description |
|---|---|---|
| status | Number | HTTP status code |
| headers | Object | Response headers (lowercase keys) |
| body | IObjectInfoHttpPayload / null | Object metadata for GET; null for HEAD |
IObjectInfoHttpPayload: id / name / version / bucket_id / size / content_type / cache_control / etag / metadata / last_modified / created_at.
getObjectInfoPublic
1. Description
Gets metadata of a public object; no authentication required. The target must be a public bucket. Only GET is supported.
Signature: app.storage.getObjectInfoPublic(options): Promise<IGetObjectInfoHttpResult>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| bucketId | Yes | String | Bucket ID (must be a public bucket) |
| objectName | Yes | String | Object name |
| envId | No | String | Overrides the current envId |
3. Return Result
Same as getObjectInfoAuthenticated; body is always an IObjectInfoHttpPayload.