在云函数上传视频的问题

发布于 6 年前作者 clei8669 次浏览最后编辑 6 年前来自 ask

在小程序里选择视频上传,在云函数里面执行函数

const fs = require(‘fs’)

const path = require(‘path’)

cloud.init({

env: ‘wl-97aae6’

})

// 云函数入口函数

var timestamp = Date.parse(new Date());

exports.main = async (event, context) => {

const filename = “video/” + timestamp + event.videourl.match(/\.[^.]+?$/)[0]

const fileStream = fs.createReadStream(path.join(__dirname, event.videourl))

return await cloud.uploadFile({

cloudPath: filename,

fileContent: fileStream

})

}

总是报这个

这个该怎么做

1 回复
jing99
jing991 楼4 年前

上传操作要放在小程序端进行,即调用wx.cloud.uploadFile,而不是在云函数里调用。