I am capable of uploading to the Cloudinary via the REST API using the Node request module like so:
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
})
})
I am only using the request for the cloudinary upload otherwise I use node-fetch throughout my application. I would like to use node-fetch for the cloudinary upload but applying the same logic as in the working example above results in the cryptic error message: 'Upload preset must be specified when using unsigned...'
My node fetch request looks like this:
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
})