微信小程序云开发SDK文档 文件存储换取真实链接


本文整理自网络,侵删。

Cloud.getTempFileURL(fileList: string[]): Promise<Object>

支持端:小程序 , 云函数 , Web

用云文件 ID 换取真实链接,公有读的文件获取的链接不会过期,私有的文件获取的链接十分钟有效期。一次最多取 50 个。

参数

fileList: string[]

要换取临时链接的云文件 ID 列表

返回值

Promise.<Object>

属性类型说明
fileListObject文件列表

fileList 的结构

属性类型说明
fileIDstring云文件 ID
tempFileURLstring临时文件路径
statusnumber状态码,0 为成功
errMsgstring成功为 ok,失败为失败原因

小程序端示例

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
}



标签:微信小程序

相关阅读 >>

微信小程序api 转发消息

微信小程序 运力方使用previewtemplate

微信小程序 消息-统一服务消息

微信小程序api 绘图setlinecap(设置线条端点样式)

微信小程序云开发服务端数据库api update

微信小程序 小程序使用reorder

服务端

sdk数据库 aggregate划分记录

微信小程序 事件

微信小程序api 音频-设置播放选项

更多相关阅读请进入《微信小程序》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...