微信小程序
getTempFileURL
# Cloud.getTempFileURL(fileList: string[]): Promise<Object>
支持端:小程序 , 云函数 , Web
用云文件 ID 换取真实链接,公有读的文件获取的链接不会过期,私有的文件获取的链接十分钟有效期。一次最多取 50 个。
# 参数
# fileList: string[]
要换取临时链接的云文件 ID 列表
# 返回值
# Promise.<Object>
fileList 的结构
# 小程序端示例
Promise 风格
wx.cloud.getTempFileURL({
fileList: [{
fileID: 'a7xzcb',
maxAge: 60 * 60, // one hour
}]
}).then(res => {
// get temp file URL
console.log(res.fileList)
}).catch(error => {
// handle error
})
Callback 风格
wx.cloud.getTempFileURL({
fileList: ['cloud://xxx', 'cloud://yyy'],
success: res => {
// get temp file URL
console.log(res.fileList)
},
fail: err => {
// handle error
}
})
# 云函数端示例
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
exports.main = async (event, context) => {
const fileList = ['cloud://xxx', 'cloud://yyy']
const result = await cloud.getTempFileURL({
fileList: fileList,
})
return result.fileList
}