I have a simple server using TSOA and I've exposed an endpoint to receive a file before persisting it to S3. The endpoint uses the built in file annotation @UploadedFile() with multer as the middleware, simple set up and works as expected when sending requests with attached files through Postman. However for some reason I cannot send the files from my client side application and am getting errors.
Here is an example
server side:
@Post('/upload')
public async upload(
@UploadedFile() file: Express.Multer.File
) {
return this.documentService.writeToS3(file.buffer)
}
client side:
const command = new S3.GetObjectCommand({
Bucket: process.env.SUPPORTAL_S3_BUCKET_NAME!,
Key: key
})
const object = await client.send(command)
const formData = new FormData()
formData.append('file', object.Body) // Body is of type StreamingBlobPayloadOutputTypes
await axios.post('http://localhost:3000.../upload', formData)
this results in the server side returning error: file is required, and I'm not sure what is causing this... Seems like a simple implementation with the field file existing in the form data. I'm unsure how this majorly differs from sending requests from Postman where I've manually set the form field to 'file'? Any help would be greatly appreciated