uni-app 云函数本地调试运行正常,部署到云端后访问报错
uni-app 云函数本地调试运行正常,部署到云端后访问报错
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
uniCloud/腾讯云 | - | - |
操作步骤:
'use strict';
const FormData = require('form-data'); // 此form-data需要使用npm安装,地址:https://www.npmjs.com/package/form-data
exports.main = async (event, context) => {
const form = new FormData()
form.append('otherParam', 'otherParam content');
const res = await uniCloud.httpclient.request('https://httpbin.org/post', {
method: 'POST',
content: form.getBuffer(), // 请求内容
headers: form.getHeaders(), // 请求头
dataType: 'json' // 此处指定为json表示将此请求的返回值解析为json
})
return res
};
预期结果:
本地调试的时候上传成功
实际结果:
部署到unicloud云函数后请求报错 form.getBuffer is not a function
bug描述:
根据 https://uniapp.dcloud.io/uniCloud/cf-functions.html#httpclient 中提供的案例
使用该方法在本地云函数调试后可以正常发送请求,但是在部署unicloud云函数后,调用该函数却报错form.getBuffer is not a function
实际的应用场景是微信apiv3的图片上传功能,需要用到foredata,贴出的demo代码用于复现bug,本地云函数可正常提交到微信,部署到云端后无法正常运行。
更多关于uni-app 云函数本地调试运行正常,部署到云端后访问报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
github上反馈换个node版本就好了的是你吗?我这用nodejs8.9腾讯云测试也没有出现你截图里面的报错,可以打印下你的formdata里面都有那些方法吗
更多关于uni-app 云函数本地调试运行正常,部署到云端后访问报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html
碰到一摸一样的问题,请问如何解决