小程序中雲函數參數的接收與傳遞/errMsg: Error: 參數值錯誤 (需要有效的ImageUrl或Imagebase64)。


調用雲函數時小程序報錯:

WAServiceMainContext.js:2 Error: cloud.callFunction:fail Error: errCode: -504002 
functions execute fail | errMsg: Error: 參數值錯誤 (需要有效的ImageUrl或Imagebase64)。

原因:對於雲函數參數傳遞與接收掌握不清楚

在小程序中使用雲函數

wx.cloud.callFunction({
  // 雲函數名稱
  name: 'todo_functions', 
  // 傳給雲函數的參數
  data: {
	name:"world !!!"
  },
  success: function(res) {
    console.log(res.result.new_name) // hello world !!!
  },
  fail: console.error
})

雲函數接收從小程序中傳遞過來的參數

在雲函數中接收js傳來的參數,並返回參數:

exports.main = async (event, context) => {
  const params = {
    "ImageUrl":event.ImageUrl
  };
}

更新雲函數(上傳並部署,雲端安裝依賴)

image


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM