May 20, 2021 WeChat Mini Program Development Document
Support: small programs, cloud functions, web
In exchange for a real link with a cloud file ID, the link obtained by the publicly read file does not expire, and the link obtained by the private file is valid for ten minutes. Take up to 50 at a time.
The list of cloud file IDs to exchange for temporary links
Property | Type | Description |
---|---|---|
fileList | Object | The list of files |
The structure of fileList
Property | Type | Description |
---|---|---|
fileID | string | Cloud file ID |
tempFileURL | string | Temporary file path |
status | number | Status code, 0 is successful |
errMsg | string | Success is ok and failure is the cause of failure |
Promise style
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 style
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
}