0

Sending an Array on form using thunder

Is there a way to send an array in the form-data format using Thunder? i need to send an array of urls on the field "redirectUrls" to test my endpoint i tried to send it as an array "redirectUrls[0]" but it's did't work any solutions ? enter image description here

1 Answers1

1

Just add multiple form fields with the same field name. Here is a working example:

import express from 'express';
import multer from 'multer';

const app = express();

const upload = multer();

app.post('/', upload.array('files'), (req, res) => {
  console.log('body: ', req.body)
  console.log('files:', req.files)
  res.sendStatus(200)
})

app.listen(3000, () => console.log('Server is listening on http://localhost:3000'))

enter image description here

Server logs:

body:  [Object: null prototype] { redirectUrls: [ 'a', 'b' ] }
files: [
  {
    fieldname: 'files',
    originalname: 'avatar1.jpg',
    encoding: '7bit',
    mimetype: 'image/jpeg',
    buffer: <Buffer ff d8 ff e1 00 18 45 78 69 66 00 00 49 49 2a 00 08 00 00 00 00 00 00 00 00 00 00 00 ff ec 00 11 44 75 63 6b 79 00 01 00 04 00 00 00 3c 00 00 ff e1 03 ... 91369 more bytes>,
    size: 91419
  },
  {
    fieldname: 'files',
    originalname: 'avatar2.jpg',
    encoding: '7bit',
    mimetype: 'image/jpeg',
    buffer: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff db 00 43 00 02 01 01 01 01 01 02 01 01 01 02 02 02 02 02 04 03 02 02 02 02 05 04 04 03 ... 35909 more bytes>,
    size: 35959
  }
]

Thunder Client v2.7.3

Lin Du
  • 88,126
  • 95
  • 281
  • 483