// 云函数入口文件
const cloud = require('wx-server-sdk')
const fs = require('fs')
const path =require('path')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
// 云函数入口函数
exports.main = async (event, context) => {
const tupian = event.tu //传进来的是一个图片的临时路径!
console.log("tupian")
console.log(tupian)
const fileStream = fs.createReadStream(path.join(__dirname,tupian))
console.log("fileStream")
console.log(fileStream)
const wxwx = await cloud.uploadFile({
cloudPath:"test.jpg",
fileContent:fileStream
})
return wxwx
}
调试错误信息:VM2540:1 Uncaught (in promise) thirdScriptError
errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID 479173ba-4fdd-11ea-8026-52540029942f, cloud function service error code -504002, error message errCode: -503001 storage request fail | errMsg: uploadFile:fail The body of your POST request is not well-formed multipart/form-data.; at uploadFile api;
Error: errCode: -503001 storage request fail | errMsg: uploadFile:fail The body of your POST request is not well-formed multipart/form-data.; at uploadFile api;