云函数上传图片问题,云函数,一直测试不成功?帮忙看看什么情况?
发布于 6 年前 作者 kongchao 10541 次浏览 来自 问答
// 云函数入口文件
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; 

2 回复

只是传过来event.tu?没有将图片内容传进来吧?

还是在小程序端上传吧

回到顶部