title: cloud

sidebar_label: cloud

Instance object of a cloud development SDK.

Reference

Type

  1. typeof cloud

Parameters

CallFunctionResult

Common return for cloud functions

Property Type Description
result `string Record` Results returned by the cloud function
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 The callback function used when the API call completed (always executed whether the call succeeds or fails)

IInitConfig

Initial configuration

Property Type Required Description
env `string { database?: string; functions?: string; storage?: string; }` No Default environment configuration, pass in an environment ID as a string to specify the default environment for all services, or pass in an object to specify the default environment for each service individually.
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 The callback function used when the API call completed (always executed whether the call succeeds or fails)
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 The callback function used when the API call completed (always executed whether the call succeeds or fails)
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 The callback function used when the API call completed (always executed whether the call succeeds or fails)
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 The callback function used when the API call completed (always executed whether the call succeeds or fails)
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 The callback function used when the API call completed (always executed whether the call succeeds or fails)
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

  1. (config?: IInitConfig) => void
Property Type
config IInitConfig

Sample Code

  1. Taro.cloud.init({
  2. env: 'test-x1dzi'
  3. })

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

  1. { (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.

  1. Taro.cloud.callFunction({
  2. // Name of the cloud function to be called
  3. name: 'add',
  4. // The event parameter passed to the cloud function.
  5. data: {
  6. x: 1,
  7. y: 2,
  8. }
  9. }).then(res => {
  10. // output: res.result === 3
  11. }).catch(err => {
  12. // handle error
  13. })

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

  1. { (param: OQ<UploadFileParam>): any; (param: Pick<UploadFileParam, "config" | "cloudPath" | "filePath" | "header">): Promise<UploadFileResult>; }
Property Type
param OQ<UploadFileParam>

Sample Code

Example 1
  1. Taro.cloud.uploadFile({
  2. cloudPath: 'example.png',
  3. filePath: '', // file path
  4. success: res => {
  5. // get resource ID
  6. console.log(res.fileID)
  7. },
  8. fail: err => {
  9. // handle error
  10. }
  11. })
Example 2
  1. Taro.cloud.uploadFile({
  2. cloudPath: 'example.png',
  3. filePath: '', // file path
  4. }).then(res => {
  5. // get resource ID
  6. console.log(res.fileID)
  7. }).catch(error => {
  8. // handle error
  9. })

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

  1. { (param: OQ<DownloadFileParam>): any; (param: Pick<DownloadFileParam, "config" | "cloudPath" | "fileID">): Promise<DownloadFileResult>; }
Property Type
param OQ<DownloadFileParam>

Sample Code

Example 1
  1. Taro.cloud.downloadFile({
  2. fileID: 'a7xzcb',
  3. success: res => {
  4. // get temp file path
  5. console.log(res.tempFilePath)
  6. },
  7. fail: err => {
  8. // handle error
  9. }
  10. })
Example 2
  1. Taro.cloud.downloadFile({
  2. fileID: 'a7xzcb'
  3. }).then(res => {
  4. // get temp file path
  5. console.log(res.tempFilePath)
  6. }).catch(error => {
  7. // handle error
  8. })

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

  1. { (param: OQ<GetTempFileURLParam>): void; (param: Pick<GetTempFileURLParam, "config" | "fileList">): Promise<GetTempFileURLResult>; }
Property Type
param OQ<GetTempFileURLParam>

Sample Code

Example 1
  1. Taro.cloud.getTempFileURL({
  2. fileList: [{
  3. fileID: 'a7xzcb',
  4. maxAge: 60 * 60, // one hour
  5. }]
  6. }).then(res => {
  7. // get temp file URL
  8. console.log(res.fileList)
  9. }).catch(error => {
  10. // handle error
  11. })
Example 2
  1. Taro.cloud.getTempFileURL({
  2. fileList: ['cloud://xxx', 'cloud://yyy'],
  3. success: res => {
  4. // get temp file URL
  5. console.log(res.fileList)
  6. },
  7. fail: err => {
  8. // handle error
  9. }
  10. })

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

  1. { (param: OQ<DeleteFileParam>): void; (param: Pick<DeleteFileParam, "config" | "fileList">): Promise<DeleteFileResult>; }
Property Type
param OQ<DeleteFileParam>

Sample Code

Example 1
  1. .cloud.deleteFile({
  2. fileList: ['a7xzcb']
  3. }).then(res => {
  4. // handle success
  5. console.log(res.fileList)
  6. }).catch(error => {
  7. // handle error
  8. })
Example 2
  1. Taro.cloud.deleteFile({
  2. fileList: ['a7xzcb'],
  3. success: res => {
  4. // handle success
  5. console.log(res.fileList)
  6. },
  7. fail: err => {
  8. // handle error
  9. },
  10. complete: res => {
  11. // ...
  12. }
  13. })

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

  1. (config?: IConfig) => Database
Property Type
config IConfig

Sample Code

Example 1

The following call obtains a reference to the database of the default environment:

  1. 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.

  1. const testDB = Taro.cloud.database({
  2. env: 'test-123'
  3. })

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 ✔️