0

I need to send an image along with other fields within an array of objects.

Body requisition:

{"items":[
{"name":"agua sem gas","image_url":"","price":0,"cost":0,"stock":0,"is_active":1,"image":{}},
{"name":"agua com gas","image_url":"","price":0,"cost":0,"stock":0,"is_active":1,"image":{}}
]}

API call:

 const response: superagent.Response = await superagent
        .post(endpoint)
        .set('Authorization', authToken)
        .ok(_ => true)
        .send({ items: drinks });

Before sending, the array has the image in the image field. However, it is not being sent when making the request.

Send the image inside the object along with other fields, without having to use the following structure.

Example taken from the documentation:

 request
       .post('/upload')
       .field('user[name]', 'Tobi')
       .field('user[email]', 'tobi@learnboost.com')
       .field('friends[]', ['loki', 'jane'])
       .attach('image', 'path/to/tobi.png')

0 Answers0