Skip to main content

Other Cloud Capabilities

$w.cloud.getTempFileURL​

$w.cloud.getTempFileURL(params: string | string[]): Promise<string | string[]>

Feature Description​

Obtain temporary access links for cloud storage files by converting private cloud://xxxx protocol addresses to standard http protocol addresses.

Note: If the cloud://xxx protocol address is incorrect or lacks access permissions, this method will not return an address.

Input Parameters​

Input parameters can be a string or string array. The value is a temporary access link. See the sample for details.

Response Parameters​

Returns the converted http address.

The input parameter is a string, and the return value is also a string.

The input parameter is an array, and the return value is an object: {key: value}. The key is the input cloud:// address, and the value is the corresponding converted address.

See the example for details.

Example​

// The input parameter is a string, and the return value is a string.
$w.cloud
.getTempFileURL(
"cloud://tcb-demo-10cf5b.7463-tcb-demo-10cf5b-1302484483/images/pic_netbian_com/001714-162653863412dd.jpg"
)
.then((url) => console.log("Request result", url));
// Request result
// https://6c4f-lowcode-9gu72kpiac8de2d6-1252394733.tcb.qcloud.la/-reservation-press@2x.png_1629354746149.png

// The input parameter is an array, and the return value is an array.
$w.cloud
.getTempFileURL([
"cloud://tcb-demo-10cf5b.7463-tcb-demo-10cf5b-1302484483/images/pic_netbian_com/001714-162653863412dd.jpg",
"cloud://tcb-demo-10cf5b.7463-tcb-demo-10cf5b-1302484483/images/pic_netbian_com/001935-16159115757f04.jpg",
])
.then((res) => {
console.log("Request result", res);
});

// Request result
// {
// 'cloud://tcb-demo-10cf5b.7463-tcb-demo-10cf5b-1302484483/images/pic_netbian_com/001714-162653863412dd.jpg': 'https://6c4f-lowcode-9gu72kpiac8de2d6-1252394733.tcb.qcloud.la/-reservation-press@2x.png_1629354746149.png',
// 'cloud://tcb-demo-10cf5b.7463-tcb-demo-10cf5b-1302484483/images/pic_netbian_com/001935-16159115757f04.jpg': 'https://6c5f-lowcode-9gu72kpiac8de2d6-1252394733.tcb.qcloud.la/-reservation-press@2x.png_1629354767798.png'
// }

$w.cloud.getCloudInstance​

$w.cloud.getCloudInstance(): Promise<CloudInstance>

Feature Description​

Get the initialized CloudBase instance in the current runtime environment (without having to manage tcb environment information or authentication/login handling), and use this object to directly call various CloudBase capabilities.

ps:

  1. If the current environment is a web environment or mini program full hosting mode, the obtained instance is a CloudBase web-sdk instance that has completed tcb.init initialization. For detailed usage, refer to the web-sdk documentation.
  2. If the current mode is Mini Program default mode, scan-code authorization, or service provider mode, the obtained instance is a WeChat CloudBase instance, having completed wx.cloud.init or wx.cloud.Cloud.init. For detailed usage, refer to the WeChat CloudBase documentation

Input Parameters​

None

Response Parameters​

Promise\<CloudInstance\>

Example​

$w.cloud.getCloudInstance().then((app) => {
// Invoke cloud function
app
.callFunction({
name: "test",
data: { a: 1 },
})
.then((res) => {
const result = res.result; // Cloud function execution result
});
});

$w.cloud.callFunction​

Invoking Cloud Development cloud functions is largely consistent with the effect in the $w.cloud.getCloudInstance example.

(params: ICallFunctionParams, parseOptions?: IParseOptions) => Promise<any>

Input Parameters​

ICallFunctionParams Parameters for invoking cloud functions​

PropertyTypeDefault ValueRequiredDescription
namestringYesCloudBase cloud function name
dataanyNoParameters received by the cloud function, depending on the input parameters of the cloud function you created.

IParseOptions Configuration for parsing Cloud Development cloud function invocation results​

PropertyTypeDefault ValueRequiredDescription
unwrapResultbooleanNoParses the generic response wrapper of Cloud Development cloud functions. When set to true, returns res.result, but loses res.requestId information.
parseBusinessInfobooleanNoParses business information and must be used in conjunction with unwrapResult. When set to true, throws an error if res.result.code is not 0, and returns res.result.data if it is 0.

Output Parameters​

The returned result depends on the user-defined cloud function implementation.

Example​

$w.cloud
.callFunction({
name: "test",
data: { a: 1 },
})
.then((res) => {
const result = res; // Cloud function execution result
});

$w.cloud.getUrlWithOpenidToken​

$w.cloud.getUrlWithOpenidToken(src: string): Promise<string>

Feature Description​

In the login authentication source settings, after enabling "WeChat Mini Program OPENID Login" for H5, this function returns an H5 redirect link containing the WeChat Mini Program authorization token parameter. This link can be used for silent OpenID authorization login in H5 pages within the WeChat Mini Program webview.

Input Parameters​

PropertyTypeDefault ValueRequiredDescription
srcstringYesWeChat Mini Program webview redirect URL

Response Parameters​

Promise\<string\>

Example​

$w.cloud.getUrlWithOpenidToken(src).then((url) => {
const result = url; // h5 redirect link containing the WeChat Mini Program authorization token parameter
});