0
我想請求來自Android應用程序post
方法使用Loopj Async Http Client
,並利用使用Multer
通過使用下面的代碼處理多POST方法請求的NodeJS拋意外的字段錯誤
步驟節點服務器處理請求-1
public static void post(String url, File entity, AsyncHttpResponseHandler responseHandler) {
RequestParams params = new RequestParams();
try {
params.put("image",entity);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
client.post(getAbsoluteUrl(url), params, responseHandler);
}
的getAbsoluteUrl返回實際的URL後請求
步驟-2(節點服務器)
router.post('/upload_image', function(req, res) {
console.log(req.files);
});
但是,接受我的節點JS服務器拋出一些錯誤這樣的要求,我無法理解,谷歌搜索和尋找其他的選擇我是幾個小時後之後仍然無力解決這個問題。
這裏是問題:
POST /upload_image 500 1537.367 ms - 2057
Error: Unexpected field
at makeError (/home/jkrishna/Documents/ProjectX/node_modules/multer/lib/make-error.js:12:13)
at wrappedFileFilter (/home/jkrishna/Documents/ProjectX/node_modules/multer/index.js:39:19)
at Busboy.<anonymous> (/home/jkrishna/Documents/ProjectX/node_modules/multer/lib/make-middleware.js:112:7)
at Busboy.EventEmitter.emit (events.js:106:17)
at Busboy.emit (/home/jkrishna/Documents/ProjectX/node_modules/multer/node_modules/busboy/lib/main.js:31:35)
at PartStream.<anonymous> (/home/jkrishna/Documents/ProjectX/node_modules/multer/node_modules/busboy/lib/types/multipart.js:213:13)
at PartStream.EventEmitter.emit (events.js:95:17)
at HeaderParser.<anonymous> (/home/jkrishna/Documents/ProjectX/node_modules/multer/node_modules/busboy/node_modules/dicer/lib/Dicer.js:51:16)
at HeaderParser.EventEmitter.emit (events.js:95:17)
at HeaderParser._finish (/home/jkrishna/Documents/ProjectX/node_modules/multer/node_modules/busboy/node_modules/dicer/lib/HeaderParser.js:68:8)
at SBMH.<anonymous> (/home/jkrishna/Documents/ProjectX/node_modules/multer/node_modules/busboy/node_modules/dicer/lib/HeaderParser.js:40:12)
at SBMH.EventEmitter.emit (events.js:95:17)
at SBMH._sbmh_feed (/home/jkrishna/Documents/ProjectX/node_modules/multer/node_modules/busboy/node_modules/dicer/node_modules/streamsearch/lib/sbmh.js:95:16)
at SBMH.push (/home/jkrishna/Documents/ProjectX/node_modules/multer/node_modules/busboy/node_modules/dicer/node_modules/streamsearch/lib/sbmh.js:56:14)
at HeaderParser.push (/home/jkrishna/Documents/ProjectX/node_modules/multer/node_modules/busboy/node_modules/dicer/lib/HeaderParser.js:46:19)
at Dicer._oninfo (/home/jkrishna/Documents/ProjectX/node_modules/multer/node_modules/busboy/node_modules/dicer/lib/Dicer.js:197:25)
你忘了說明你是如何設置multer中間件的。 – mscdex
@mscdex,我已經用這種方式添加了multer app.use(multer({dest:images_path})。single('file')); –