vonage-node-code-snippets
vonage-node-code-snippets copied to clipboard
Media Upload - Whatsapp template management API example code snippets
Can you please provide an example for the media upload https://developer.vonage.com/en/api/whatsapp-template-management#MediaUpload
Please correct me where it is going wrong
Expected Behavior
It should give a successful response
Current Behavior
Throwing error
data: { type: 'https://developer.vonage.com/api-errors', title: 'Internal Server Error', instance: '1e5451e9-485d-400e-b766-cdf6ae8b266d' }
Context (Environment)
Typescript, Node v18.16.0
Steps to Reproduce
import axios from 'axios'
var FormData = require('form-data')
async function main() {
const imageUrl = `https://fastly.picsum.photos/id/823/536/354.jpg?hmac=ysg16ZYU5mSoAtbckBDDJqI-QuuNe0YouKOIgHneSYw`
const imageResponse = await axios.get(imageUrl, {
responseType: 'arraybuffer',
})
console.log('Content-Type:', imageResponse.headers['content-type'])
let formData = new FormData()
formData.append('mediafile', imageResponse.data)
const uploadMedia = await axios({
method: 'post',
url: `https://api.nexmo.com/v2/whatsapp-manager/media/uploads?file_type=image%2Fjpeg`,
headers: {
'Content-Type': 'multipart/form-data',
Authorization: `Bearer xxxx`,
},
data: formData,
})
console.log(`Upload Media: ${JSON.stringify(uploadMedia.data)}`)
}
main()