英文:
How to send an array with Thunder in form-data format?
问题
使用Thunder发送数组形式的表单数据
是否有办法使用Thunder以表单数据的格式发送一个数组?我需要将一个URL数组发送到字段"redirectUrls"以测试我的端点,我尝试将它作为数组"redirectUrls[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 ?
答案1
得分: 1
只需添加具有相同字段名称的多个表单字段。以下是一个可工作的示例:
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'))
服务器日志:
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
英文:
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'))
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论