阅读(3735) (7)

微信小程序云开发服务端存储API 从云存储空间下载文件

2018-11-20 14:25:33 更新

downloadFile

从云存储空间下载文件

请求参数

字段说明数据类型默认值必填
fileID云文件 IDString-Y

Promise 返回参数

字段说明数据类型
fileContent文件内容Buffer
statusCode服务器返回的 HTTP 状态码Number

错误返回参数

字段说明数据类型
errCode错误码Number
errMsg错误信息,格式 apiName:fail msgString

使用示例

Promise 风格

const cloud = require('wx-server-sdk')

exports.main = async (event, context) => {
  const fileID = 'xxxx'
  const res = await cloud.downloadFile({
    fileID: fileID,
  })
  const buffer = res.fileContent
  return buffer.toString('utf8')
}