云函数代码:
输出:
body:
buffer:
云存储结果:文件大小10K
请求成功的代码:
//获取体验版二维码
function getQrCode(access_token,appId) {
return new Promise((resolve, reject) => {
request({
url: `https://api.weixin.qq.com/wxa/get_qrcode?access_token=${access_token}`,
headers: {
'Accept-Encoding': 'gzip, deflate'
},
encoding: null
}, (error, response, body) => {
if (error) {
console.log('getQrCode失败:',error);
reject(error);
}
const fileExtension = 'jpeg';
cloud.uploadFile({
cloudPath: `${appId}.${fileExtension}`,
fileContent: body
}).then(res=>{
if (!res.fileID) {
reject(res)
}
resolve(res.fileID);
})
});
});
}
请求里添加参数:
headers: {
'Accept-Encoding': 'gzip, deflate'
},
encoding: null