2012-07-13 58 views
-1

我想上傳大文件(〜2 GB)。我已經從Express中刪除了bodyParser以停止服務器崩潰的巨大文件。崩潰錯誤也是間歇性的,所以我什至不能選擇錯誤發生的原因,以及爲什麼。在我的網頁瀏覽器中的強大崩潰

的代碼如下:

channel = req.params.channel 
    models.channel.findOne name: channel, (err, show) -> 
    if err then console.log err 
    if show? 
     form = formidable.IncomingForm() 
     files = [] 
     fields = [] 
     form.uploadDir = __dirname + '/../public/videos/resources/' 

     form.on 'field', (field, value) -> 
     #console.log field + ' ' + value 
     fields.push [field,value] 

     form.on 'file', (field, file) -> 
     #console.log file 
     files.push [field, file] 

     form.on 'end', -> 
     for file in files 
      filename = file[1].name.replace /(.*)\//, '' 
      ext = file[1].name.replace /(.*)\./, '' 
      filename = uuid("#{filename}" + Date.now()) + ".#{ext}" 
      fs.renameSync file[1].path, form.uploadDir + filename 
      v = new models.video 
      v.channel_id = channel._id 
      v.title = 'Episode' 
      v.description = '' 
      v.url = filename 

      v.save (err,results) -> 
      if err then console.log err 
      res.send 200 

     form.parse req 
    else 
     res.send 403 

有時上傳將工作,有時它會彈了出來有以下幾點:

Error: parser error, 0 of 65536 bytes parsed 
    at IncomingForm.write (/Users/brendan/github/node_modules/formidable/lib/incoming_form.js:145:17) 
    at IncomingMessage.<anonymous> (/Users/brendan/github/node_modules/formidable/lib/incoming_form.js:95:12) 
    at IncomingMessage.emit (events.js:67:17) 
    at HTTPParser.parserOnBody [as onBody] (http.js:105:21) 
    at Socket.ondata (http.js:1506:22) 
    at TCP.onread (net.js:374:27) 

有其他人遇到這個問題,或者知道是什麼是造成這個?

+0

完全誤導性標題:厲害不*瀏覽器*運行。 – 2014-02-10 10:54:08

回答

0

我遇到過類似的錯誤,問題是由我的中間件對數據庫的異步調用引起的。在設置請求數據事件的任何處理程序之前發送異步調用。這導致難以丟失數據。

可能相關鏈接:

https://github.com/felixge/node-formidable/issues/130

https://github.com/felixge/node-formidable/issues/34

編輯

中間件

getCategories = (req, res, next) -> 
    data.getCategories (err, results) -> 
    res.locals.categories = results 
    next() 

查詢

data.getCategories = (callback) -> 
    pg.connect connString, (err, client) -> 
     client.query "SELECT name, slug FROM categories", (err, result) -> 
      callback err, result.rows 
+0

你對中間件內的數據庫做了什麼? – Menztrual 2012-07-13 10:34:35