enctype multipart/form-data
을 사용하는 데 문제가 있으며 동일한 이름의 입력을 배열로 가져올 수 있습니다. 난 단지배열을 사용하는 NodeJS 다중 폼/양식 데이터
, 나는이 양식을 가지고 ... 같은 시간에 업로드 된 이미지 또는 배열 입력 있지만 둘을 얻을 보일 수있다 :
<form method="post" action="/test">
<input name="testinput" value="valueA">
<input name="testinput" value="valueB">
<input type="file" name="fileattachment">
<input type="submit" value="Submit">
</form>
내가 폼의 PHP 버전을 설정하는 경우 내 NodeJS 응용 프로그램에서 바로 벌금 'fileattachment'을 받고 결국
<form method="post" action="/test" enctype="multipart/form-data">
,하지만 난 단지 같이, 'testinput'에 대한 마지막 값을 얻을 : 같은, multipart/form-data
수
의 'testinput'데이터 배열로 제공하지만,이처럼 'fileattachment은'손실되고 난 단지 업로드 된 파일의 이름을 얻을 :
//req.body
//---
{
testinput: ['valueA', 'valueB'],
fileattachment: 'some_picture.png' // Useless for file uploading
}
I 그것은 내가 표현한 'body parser'를 설정 한 방식과 관련이 있다고 생각하지만 올바른 설정을 파악할 수 없다. 이것은 내 (관련 코드를 단순화) 설정입니다 : 내가 본 적이이 node/6.9.1
에서 실행되는
{
"name": "my-app",
...
"dependencies": {
"body-parser": "~1.15",
"express": "~4.14",
"express-fileupload": "^0.0.5"
}
}
: 또한
var express = require('express');
var fileUpload = require('express-fileupload');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(fileUpload()); // Must be placed after, not before, bodyparser's use, otherwise files fail to be uploaded correctly...
app.post('/test', function(req, res) {
// Some code
});
이 내 package.json 파일입니다 매우 비슷한 질문 Multipart/form-data with arrays이지만, 2 세이며, 답이없고 의존성을 사용하지 않는 것 같습니다 fileUpload
.
또한, 나는이 질문에 Handling input arrays in Express forms?에 대한 대답에 의해 제안 된 접근 방법을 시도하지만 서버가 외모에 계속 점점 모든이 같은 배열 대신 텍스트입니다 : 나는 무엇을 놓치고
{
'something[0][testinput]': 'valueA',
'something[1][testinput]': 'valueB'
}
? 무엇을 시도해야합니까?
var express = require('express');
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
내 코드 :
var multiparty = require('multiparty');
app.post('/test', function(req, res) {
(new multiparty.Form()).parse(req, function(err, fields, files) {
// handling fields and files code
});
});
필드 :
{
testinput: ['valueA', 'valueB']
}
,369