收藏
回答

云函数上传图片问题,云函数,一直测试不成功?帮忙看看什么情况?

// 云函数入口文件
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 个回答

  • 一ืุ笑ืุ而ืุ过ืุ
    一ืุ笑ืุ而ืุ过ืุ
    2020-07-19

    我也遇到这个问题了,题主解决了吗?

    2020-07-19
    有用
    回复 1
    • 一ืุ笑ืุ而ืุ过ืุ
      一ืุ笑ืุ而ืุ过ืุ
      2020-07-19
      云函数端属于nodejs后端,要在后端上传文件起码要有个文件夹来存放图片,起码要用fs模块读取出来
      2020-07-19
      回复
  • 老张
    老张
    2020-02-15

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

    2020-02-15
    有用
    回复 3
登录 后发表内容
问题标签