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 stringCall result
IAPIParam Common parameters for cloud functions
Property Type Required Description config IConfigNo Configuration success (res: T) => voidNo The callback function for a successful API call fail (err: CallbackResult) => voidNo 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 booleanNo Specify whether or not user access is logged to User Management before being visible in the console.
IConfig Configuration
Property Type Required Description env stringNo The environment ID used, which can be filled in to ignore the environment specified by init. traceUser booleanNo 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 IConfigNo Configuration
CallFunctionParam Property Type Required Description name stringYes 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 booleanNo config IConfigNo Configuration complete `(res: CallFunctionResult CallbackResult) => void` No fail (res: CallbackResult) => voidNo The callback function for a failed API call success (res: CallFunctionResult) => voidNo The callback function for a successful API call
UploadFileResult Results of uploaded files
Property Type Description fileID stringFile ID statusCode numberThe HTTP status code returned by the server. errMsg stringCall result
UploadFileParam Parameters of uploaded files
Property Type Required Description cloudPath stringYes Cloud Storage Path filePath stringYes The path of the file resource to be uploaded. header Record<string, any>No config IConfigNo Configuration complete `(res: CallbackResult UploadFileResult) => void` No fail (res: CallbackResult) => voidNo The callback function for a failed API call success (res: UploadFileResult) => voidNo The callback function for a successful API call
DownloadFileResult 下载文件结果
Property Type Description tempFilePath stringTemporary file path statusCode numberThe HTTP status code returned by the server. errMsg stringCall result
DownloadFileParam Parameters for downloading files
Property Type Required Description fileID stringYes Cloud File ID cloudPath stringNo config IConfigNo Configuration complete `(res: CallbackResult DownloadFileResult) => void` No fail (res: CallbackResult) => voidNo The callback function for a failed API call success (res: DownloadFileResult) => voidNo 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 stringCall result
GetTempFileURLResultItem List of files
Property Type Description fileID stringCloud file ID tempFileURL stringThe path of the temporary file. maxAge numberstatus numberStatus Code errMsg stringCall result
GetTempFileURLParam Parameters of get temporary file
Property Type Required Description fileList string[]Yes config IConfigNo Configuration complete `(res: CallbackResult GetTempFileURLResult) => void` No fail (res: CallbackResult) => voidNo The callback function for a failed API call success (res: GetTempFileURLResult) => voidNo The callback function for a successful API call
DeleteFileResult The result of deleting a file
Property Type Description fileList DeleteFileResultItem[]List of files errMsg stringCall result
DeleteFileResultItem Delete file list
Property Type Description fileID stringCloud file ID status numberStatus Code errMsg stringCall result
DeleteFileParam Property Type Required Description fileList string[]Yes List of files config IConfigNo Configuration complete `(res: CallbackResult DeleteFileResult) => void` No fail (res: CallbackResult) => voidNo The callback function for a failed API call success (res: DeleteFileResult) => voidNo 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 Copy Property Type config IInitConfig
Sample Code Taro . cloud . init ( { env : 'test-x1dzi' } ) Copy 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 > ; } Copy 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 => { } ) Copy 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 > ; } Copy Property Type param OQ<UploadFileParam>
Sample Code Example 1 Taro . cloud . uploadFile ( { cloudPath : 'example.png' , filePath : '' , success : res => { console . log ( res . fileID ) } , fail : err => { } } ) Copy Example 2 Taro . cloud . uploadFile ( { cloudPath : 'example.png' , filePath : '' , } ) . then ( res => { console . log ( res . fileID ) } ) . catch ( error => { } ) Copy 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 > ; } Copy Property Type param OQ<DownloadFileParam>
Sample Code Example 1 Taro . cloud . downloadFile ( { fileID : 'a7xzcb' , success : res => { console . log ( res . tempFilePath ) } , fail : err => { } } ) Copy Example 2 Taro . cloud . downloadFile ( { fileID : 'a7xzcb' } ) . then ( res => { console . log ( res . tempFilePath ) } ) . catch ( error => { } ) Copy 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 > ; } Copy 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 => { } ) Copy Example 2 Taro . cloud . getTempFileURL ( { fileList : [ 'cloud://xxx' , 'cloud://yyy' ] , success : res => { console . log ( res . fileList ) } , fail : err => { } } ) Copy 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 > ; } Copy Property Type param OQ<DeleteFileParam>
Sample Code Example 1 . cloud . deleteFile ( { fileList : [ 'a7xzcb' ] } ) . then ( res => { console . log ( res . fileList ) } ) . catch ( error => { } ) Copy Example 2 Taro . cloud . deleteFile ( { fileList : [ 'a7xzcb' ] , success : res => { console . log ( res . fileList ) } , fail : err => { } , complete : res => { } } ) Copy 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 Copy 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 ( ) Copy 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' } ) Copy 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 ✔️