My code like this :
const axios = require('axios').default
import FormData from 'form-data'
import fs from 'fs'
export default class MyController {
public async handleMultipleFile({ request }: HttpContextContract) {
if(request.files('files').length > 0){
const formData = new FormData()
for( let i = 0; i < request.files('files').length; i++ ) {
let file = request.files('files')[i]
formData.append('files[' + i + ']', file)
}
axios.post(`https://example-api.com/assets/files`, formData, {
headers: {
'Content-Type': 'multipart/form-data'
},
}
).then(res => console.log(res.data))
.catch(err => console.error(err))
}
}
}
When I call the code from postman, I find this error "message": "source.on is not a function"
I add return
to see the formData in the postman
I had install library form data and axios in my code and I had import it
I want to post multiple file to a external api
How can I solve this problem? Please help. Thanks