.
270315475
- 发布:2024-09-25 17:11
- 更新:2024-09-29 20:30
- 阅读:135
产品分类: uniCloud/App
示例代码:
操作步骤:
.
.
预期结果:
.
.
实际结果:
.
.
bug描述:
'use strict';
const fs = require('fs')
const path = require('path')
const FormData = require('form-data');
exports.main = async (event, context) => {
const form = new FormData();
const { filename, contentType, buffer } = await resolveFile(
event.thumb
);
form.append("media", buffer, {
filename,
contentType,
});
const res = await uniCloud.httpclient.request('https://api.weixin.qq.com/cgi-bin/material/add_material?type=image&access_token=123', {
method: 'POST',
content: form.getBuffer(),
headers: form.getHeaders(),
dataType: 'json'
})
return res
};
这是一个给腾讯发送图片,但是要求固定ip所以要更换成uniCloud.httpProxyForEip.postJson
const images = await uniCloud.httpProxyForEip.postForm(
`https://api.weixin.qq.com/cgi-bin/material/add_material?type=image&access_token=${token.data[0].authorizer_access_token}`,
form.getBuffer(),
form.getHeaders()
);
但是一直错误"body": "{\"errcode\":41005,\"errmsg\":\"media data missing hint: [Z1Apna0212p504] rid: 66f3d2ab-6735de3e-41e14703\"}",
1 个回复
DCloud_uniCloud_WYQ
阿里云提供的固定ip方案不支持post formdata类型,这个postForm方法对应的body是application/x-www-form-urlencoded类型,你这个需求建议使用另外两个云厂商的云函数