【发布时间】:2020-05-19 13:15:37
【问题描述】:
我能够使用节点request module 通过 REST API 上传到 Cloudinary,如下所示:
request.post({
url: `https://api.cloudinary.com/v1_1/dennis/image/upload`,
body: {
file: `data:image/jpeg;base64,${req.body.toString('base64')}`,
api_key: key,
folder: 'dennis',
timestamp: ts,
signature: sig
},
json: true
}, async (err, response, body) => {
if (err) return console.error(err)
res.send({
'public_id': body.public_id,
'secure_url': body.secure_url
})
})
我只使用云上传请求,否则我在整个应用程序中使用 node-fetch。我想使用 node-fetch 进行 cloudinary 上传,但应用与上面工作示例中相同的逻辑会导致神秘的错误消息:'Upload preset must be specified when using unsigned...'
我的节点获取请求如下所示:
let response = await fetch(
`https://api.cloudinary.com/v1_1/dennis/image/upload`,
{
method: 'post',
body: {
file: `data:image/jpeg;base64,${req.body.toString('base64')}`,
api_key: key,
folder: 'dennis',
timestamp: ts,
signature: sig
}
})
if (response.status === 400) return console.error(response)
let body = await response.json()
res.send({
'public_id': body.public_id,
'secure_url': body.secure_url
})
【问题讨论】:
-
@technophyle 我使用的是签名上传,而不是未签名。
标签: node.js post request fetch cloudinary