2017-04-15 87 views
2

當客戶端應用程序嘗試發送帶有base64編碼圖像的POST請求時,服務器正在拋出此錯誤。快速:錯誤在readStream

Error 
    at readStream (/Users/.../node_modules/raw-body/index.js:196:17) 
    at getRawBody (/Users/.../node_modules/raw-body/index.js:106:12) 
    at read (/Users/.../node_modules/body-parser/lib/read.js:76:3) 
    at jsonParser (/Users/.../node_modules/body-parser/lib/types/json.js:127:5) 
    at Layer.handle [as handle_request] (/Users/.../node_modules/express/lib/router/layer.js:95:5) 
    at trim_prefix (/Users/.../node_modules/express/lib/router/index.js:317:13) 
    at /Users/.../node_modules/express/lib/router/index.js:284:7 
    at Function.process_params (/Users/.../node_modules/express/lib/router/index.js:335:12) 
    at next (/Users/.../node_modules/express/lib/router/index.js:275:10) 
    at cors (/Users/.../node_modules/cors/lib/index.js:179:7) 
    at /Users/.../node_modules/cors/lib/index.js:229:17 
    at originCallback (/Users/.../node_modules/cors/lib/index.js:218:15) 
    at /Users/.../node_modules/cors/lib/index.js:223:13 
    at optionsCallback (/Users/.../node_modules/cors/lib/index.js:204:9) 
    at corsMiddleware (/Users/.../node_modules/cors/lib/index.js:209:7) 
    at Layer.handle [as handle_request] (/Users/.../node_modules/express/lib/router/layer.js:95:5) 

我已經doublechecked請求正文:base64字符串沒有格式錯誤。如果應用在沒有base64部件的情況下發送相同請求,則一切正常。

server.js:

import http from 'http' 
import express from 'express' 
import cors from 'cors' 
import morgan from 'morgan' 
import bodyParser from 'body-parser' 
import api from './api' 
import config from './config' 

let app = express() 
app.server = http.createServer(app) 

// logger 
app.use(morgan('dev')) 

// 3rd party middleware 
app.use(cors({ 
    exposedHeaders: config.corsHeaders 
})) 

app.use(bodyParser.json({ 
    limit : config.bodyLimit 
})) 

app.use(express.static("./assets")) 

// api router 
app.use('/api', api) 

app.server.listen(process.env.PORT || config.port) 

console.log(`Started on port ${app.server.address().port}`) 

export default app 

api.js

import { Router } from 'express'; 
const router = Router(); 

router.post('/createPost', require('./methods/createPost').default) 

export default router 
+0

FWIW我有完全相同的問題。如果我通過一個小的測試體發佈請求,它會成功通過,但如果我的請求體較大(音頻 - 視頻數據),則會顯示上述錯誤。 – TonyM

回答

5

我認爲這是與此相同的問題:

Error: request entity too large

身體解析器的限制設置得太低(默認是100k)。

以我爲例,我發現,設定限制:如在鏈接的解決方案描述的「50MB」上面固定我的問題:

app.use(bodyParser.json({limit: '50mb'})); 

它看起來像你的極限在配置設定。