I'm having trouble uploading images via REST-API to Apostrophe-CMS. I use an express Proxy, so the file is not sent directly from form submit. Instead, I send it base64 encoded to my proxy server and from there to apostrophe. Here's my express code:
app.post('/update-image', function (req, res) {
const image = req.body.image
if (image) {
api.post('attachments', {file: image}, {
headers: { 'Content-Type': 'multipart/form-data' }
}).then(response => {
console.log(response)
}).catch(error => {
console.log('error:', error)
})
}
})
But what I get is "Error: content-type missing boundary". I tried to manually set "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" - this fixed this error but another one says "stream ended unexpectedly". I've also tried to convert it back to an image file with the same outcome. If I use Postman, everything works fine.
What am I doing wrong?