簡體   English   中英

如何使用 Restify 服務器在 GridFS 中存儲請求正文?

[英]How to store request body in GridFS using Restify server?

無法保存大於管道塊大小 (~64K) 的文件。

使用mongodb 3.4.0,相關節點依賴

  • 修復 4.2.0
  • mongodb ^2.2.12
  • 洛達什 4.16.6

     bookeeppingData = {request, id, ...meta} clone = lodash.cloneDeep(bookkeepingData) const { request: req, id: _id, meta: metadata, } = clone const bucket = new mongodb.GridFSBucket( db, {bucketName: 'my_gridfs_collection'} ); const uploadSteam = bucket.openUploadStreamWithId( _id, undefined, {metadata} ); req.on('data', (chunk) => { console.log(`Received ${chunk.length} bytes of data.`); }); req.on('end', () => { console.log('There will be no more data.'); }); req.on('error', (e) => { console.log('req on error', e); }); uploadSteam.on('finish', function() { console.log('finsish'); keepThebooks(bookkeepingData); }); uploadSteam.on('error', (e) => { console.log('uploadstream on error', e); }); req.pipe(uploadSteam);

    }

發送小於~64K的文件時,控制台輸出為

Received 57259 bytes of data.
There will be no more data.
finish

這是相應的 curl --verbose 輸出(減去 json 響應):

*   Trying ::1...                                                                                                                                                                             
* TCP_NODELAY set                                                                                                                                                                             
* Connected to localhost (::1) port 8060 (#0)                                                                                                                                                 
* Server auth using Basic with user 'driver'                                                                                                                                                  
> POST /artifact?branch=xyz&role=PHOTO&where.lat=55&where.long=77.2&where.acc=12&sys=system&id=1234&sys=system2&id=1234b&created=2018-11-01T18:41:50.850Z&tz=-600 HTTP/1.1                    
> Host: localhost:8060                                                                                                                                                                        
> Authorization: Basic xxxxxxxxx                                                                                                                                                   
> User-Agent: curl/7.61.1                                                                                                                                                                     
> Accept: */*
> Content-Type: image/png
> Content-Length: 57259
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 200 OK
< Cache-Control: no-cache, no-store, must-revalidate
< Content-Type: application/json
< Content-Length: 388
< Date: Wed, 23 Jan 2019 20:58:16 GMT
< Connection: keep-alive
<
* Connection #0 to host localhost left intact

發送大於 ~64K 的文件時,控制台輸出為:

Received 65536 bytes of data.

(就是這樣 - 沒有錯誤)

相應的 curl --verbose 輸出是:

*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8060 (#0)
* Server auth using Basic with user 'driver'
> POST /artifact?branch=xyz&role=PHOTO&where.lat=55&where.long=77.2&where.acc=12&sys=system&id=1234&sys=system2&id=1234b&created=2018-11-01T18:41:50.850Z&tz=-600 HTTP/1.1
> Host: localhost:8060
> Authorization: Basic xxxxxxxxx
> User-Agent: curl/7.61.1
> Accept: */*
> Content-Type: image/png
> Content-Length: 84801
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server

我希望這可以工作,並且控制台應該是這樣的:

Received 65536 bytes of data.
Received 19274 bytes of data.
There will be no more data.
finish

我在同一個團隊。 原來我們正在深度克隆包含流的對象。 當我們停止克隆整個文件上傳正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM