Instance object of a cloud development SDK.
Reference
Type
Parameters
CallFunctionResult
Common return for cloud functions
| Property | Type | Description |
|---|
| result | `string | Record<string, any>` |
| errMsg | string | Call result |
IAPIParam
Common parameters for cloud functions
| Property | Type | Required | Description |
|---|
| config | IConfig | No | Configuration |
| success | (res: T) => void | No | The callback function for a successful API call |
| fail | (err: CallbackResult) => void | No | The callback function for a failed API call |
| complete | `(val: CallbackResult | T) => void` | No |
IInitConfig
Initial configuration
| Property | Type | Required | Description |
|---|
| env | `string | { database?: string; functions?: string; storage?: string; }` | No |
| traceUser | boolean | No | Specify whether or not user access is logged to User Management before being visible in the console. |
IConfig
Configuration
| Property | Type | Required | Description |
|---|
| env | string | No | The environment ID used, which can be filled in to ignore the environment specified by init. |
| traceUser | boolean | No | Specify whether or not user access is logged to User Management before being visible in the console. |
ICloudAPIParam
Common parameters for the Cloud Functions API.
| Property | Type | Required | Description |
|---|
| config | IConfig | No | Configuration |
CallFunctionParam
| Property | Type | Required | Description |
|---|
| name | string | Yes | Cloud function name |
| data | Record<string, any> | No | The parameters passed to the cloud function are available in the cloud function via the event parameter. |
| slow | boolean | No | |
| config | IConfig | No | Configuration |
| complete | `(res: CallFunctionResult | CallbackResult) => void` | No |
| fail | (res: CallbackResult) => void | No | The callback function for a failed API call |
| success | (res: CallFunctionResult) => void | No | The callback function for a successful API call |
UploadFileResult
Results of uploaded files
| Property | Type | Description |
|---|
| fileID | string | File ID |
| statusCode | number | The HTTP status code returned by the server. |
| errMsg | string | Call result |
UploadFileParam
Parameters of uploaded files
| Property | Type | Required | Description |
|---|
| cloudPath | string | Yes | Cloud Storage Path |
| filePath | string | Yes | The path of the file resource to be uploaded. |
| header | Record<string, any> | No | |
| config | IConfig | No | Configuration |
| complete | `(res: CallbackResult | UploadFileResult) => void` | No |
| fail | (res: CallbackResult) => void | No | The callback function for a failed API call |
| success | (res: UploadFileResult) => void | No | The callback function for a successful API call |
DownloadFileResult
下载文件结果
| Property | Type | Description |
|---|
| tempFilePath | string | Temporary file path |
| statusCode | number | The HTTP status code returned by the server. |
| errMsg | string | Call result |
DownloadFileParam
Parameters for downloading files
| Property | Type | Required | Description |
|---|
| fileID | string | Yes | Cloud File ID |
| cloudPath | string | No | |
| config | IConfig | No | Configuration |
| complete | `(res: CallbackResult | DownloadFileResult) => void` | No |
| fail | (res: CallbackResult) => void | No | The callback function for a failed API call |
| success | (res: DownloadFileResult) => void | No | The callback function for a successful API call |
GetTempFileURLResult
The result of the acquisition of temporary documents.
| Property | Type | Description |
|---|
| fileList | GetTempFileURLResultItem[] | List of files |
| errMsg | string | Call result |
GetTempFileURLResultItem
List of files
| Property | Type | Description |
|---|
| fileID | string | Cloud file ID |
| tempFileURL | string | The path of the temporary file. |
| maxAge | number | |
| status | number | Status Code |
| errMsg | string | Call result |
GetTempFileURLParam
Parameters of get temporary file
| Property | Type | Required | Description |
|---|
| fileList | string[] | Yes | |
| config | IConfig | No | Configuration |
| complete | `(res: CallbackResult | GetTempFileURLResult) => void` | No |
| fail | (res: CallbackResult) => void | No | The callback function for a failed API call |
| success | (res: GetTempFileURLResult) => void | No | The callback function for a successful API call |
DeleteFileResult
The result of deleting a file
| Property | Type | Description |
|---|
| fileList | DeleteFileResultItem[] | List of files |
| errMsg | string | Call result |
DeleteFileResultItem
Delete file list
| Property | Type | Description |
|---|
| fileID | string | Cloud file ID |
| status | number | Status Code |
| errMsg | string | Call result |
DeleteFileParam
| Property | Type | Required | Description |
|---|
| fileList | string[] | Yes | List of files |
| config | IConfig | No | Configuration |
| complete | `(res: CallbackResult | DeleteFileResult) => void` | No |
| fail | (res: CallbackResult) => void | No | The callback function for a failed API call |
| success | (res: DeleteFileResult) => void | No | The callback function for a successful API call |
init
The initialisation method init needs to be called once before calling the cloud development APIs (only once globally, only the first time takes effect if called multiple times)
Reference
(config?: IInitConfig) => void
| Property | Type |
|---|
| config | IInitConfig |
Sample Code
Taro.cloud.init({
env: 'test-x1dzi'
})
API Support
| API | WeChat Mini-Program | Baidu Smart-Program | Alipay Mini-Program | ByteDance Mini-Program | QQ Mini-Program | H5 | React Native | Quick App |
|---|
| cloud.init | ✔️ | | | | | | | |
callFunction
Call Cloud funtion
Reference
{ (param: OQ<CallFunctionParam>): void; (param: Pick<CallFunctionParam, "name" | "data" | "slow" | "config">): Promise<CallFunctionResult>; }
| Property | Type |
|---|
| param | OQ<CallFunctionParam> |
Sample Code
Assuming there is already a cloud function add, initiate a call to the cloud function add on the mini program side.
Taro.cloud.callFunction({
name: 'add',
data: {
x: 1,
y: 2,
}
}).then(res => {
}).catch(err => {
})
API Support
| API | WeChat Mini-Program | Baidu Smart-Program | Alipay Mini-Program | ByteDance Mini-Program | QQ Mini-Program | H5 | React Native | Quick App |
|---|
| cloud.callFunction | ✔️ | | | | | | | |
uploadFile
Upload local resources to cloud storage, or overwrite if uploading to the same path.
Reference
{ (param: OQ<UploadFileParam>): any; (param: Pick<UploadFileParam, "config" | "cloudPath" | "filePath" | "header">): Promise<UploadFileResult>; }
| Property | Type |
|---|
| param | OQ<UploadFileParam> |
Sample Code
Example 1
Taro.cloud.uploadFile({
cloudPath: 'example.png',
filePath: '',
success: res => {
console.log(res.fileID)
},
fail: err => {
}
})
Example 2
Taro.cloud.uploadFile({
cloudPath: 'example.png',
filePath: '',
}).then(res => {
console.log(res.fileID)
}).catch(error => {
})
API Support
| API | WeChat Mini-Program | Baidu Smart-Program | Alipay Mini-Program | ByteDance Mini-Program | QQ Mini-Program | H5 | React Native | Quick App |
|---|
| cloud.uploadFile | ✔️ | | | | | | | |
downloadFile
Download files from cloud storage.
Reference
{ (param: OQ<DownloadFileParam>): any; (param: Pick<DownloadFileParam, "config" | "cloudPath" | "fileID">): Promise<DownloadFileResult>; }
| Property | Type |
|---|
| param | OQ<DownloadFileParam> |
Sample Code
Example 1
Taro.cloud.downloadFile({
fileID: 'a7xzcb',
success: res => {
console.log(res.tempFilePath)
},
fail: err => {
}
})
Example 2
Taro.cloud.downloadFile({
fileID: 'a7xzcb'
}).then(res => {
console.log(res.tempFilePath)
}).catch(error => {
})
API Support
| API | WeChat Mini-Program | Baidu Smart-Program | Alipay Mini-Program | ByteDance Mini-Program | QQ Mini-Program | H5 | React Native | Quick App |
|---|
| cloud.downloadFile | ✔️ | | | | | | | |
getTempFileURL
Exchange your cloud file ID for a real link. Links obtained from public and readable files do not expire, while links obtained from private files are valid for ten minutes. Maximum of 50 at a time.
Reference
{ (param: OQ<GetTempFileURLParam>): void; (param: Pick<GetTempFileURLParam, "config" | "fileList">): Promise<GetTempFileURLResult>; }
| Property | Type |
|---|
| param | OQ<GetTempFileURLParam> |
Sample Code
Example 1
Taro.cloud.getTempFileURL({
fileList: [{
fileID: 'a7xzcb',
maxAge: 60 * 60,
}]
}).then(res => {
console.log(res.fileList)
}).catch(error => {
})
Example 2
Taro.cloud.getTempFileURL({
fileList: ['cloud://xxx', 'cloud://yyy'],
success: res => {
console.log(res.fileList)
},
fail: err => {
}
})
API Support
| API | WeChat Mini-Program | Baidu Smart-Program | Alipay Mini-Program | ByteDance Mini-Program | QQ Mini-Program | H5 | React Native | Quick App |
|---|
| cloud.getTempFileURL | ✔️ | | | | | | | |
deleteFile
Delete files from cloud storage, up to 50 at a time.
Reference
{ (param: OQ<DeleteFileParam>): void; (param: Pick<DeleteFileParam, "config" | "fileList">): Promise<DeleteFileResult>; }
| Property | Type |
|---|
| param | OQ<DeleteFileParam> |
Sample Code
Example 1
.cloud.deleteFile({
fileList: ['a7xzcb']
}).then(res => {
console.log(res.fileList)
}).catch(error => {
})
Example 2
Taro.cloud.deleteFile({
fileList: ['a7xzcb'],
success: res => {
console.log(res.fileList)
},
fail: err => {
},
complete: res => {
}
})
API Support
| API | WeChat Mini-Program | Baidu Smart-Program | Alipay Mini-Program | ByteDance Mini-Program | QQ Mini-Program | H5 | React Native | Quick App |
|---|
| cloud.deleteFile | ✔️ | | | | | | | |
database
Get the database instance.
Reference
(config?: IConfig) => Database
| Property | Type |
|---|
| config | IConfig |
Sample Code
Example 1
The following call obtains a reference to the database of the default environment:
const db = Taro.cloud.database()
Example 2
Assuming an environment named test-123 is used as a test environment, the test environment database can be obtained as follows.
const testDB = Taro.cloud.database({
env: 'test-123'
})
API Support
| API | WeChat Mini-Program | Baidu Smart-Program | Alipay Mini-Program | ByteDance Mini-Program | QQ Mini-Program | H5 | React Native | Quick App |
|---|
| cloud.database | ✔️ | | | | | | | |