[英]How to store request body in GridFS using Restify server?
无法保存大于管道块大小 (~64K) 的文件。
使用mongodb 3.4.0,相关节点依赖
洛达什 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.