The front-end uploads a file file through formdata
The back-end framework is koa, and the co-busboy middleware is used to parse the request.
There is a simple example in the co-busboy document that can obtain a "file stream" through parsing "FileStream, and then write the file locally through the fs module of node. This is quite simple.
Now my problem is that I want to store the file in the form of blob instead of storing it locally.
Then I am thinking about how to transfer from FileStream.
This FileStream is printed as follows:
FileStream {
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: [Object], tail: [Object], length: 1 },
length: 10256,
pipes: null,
pipesCount: 0,
flowing: null,
ended: false,
endEmitted: false,
reading: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events: { end: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
truncated: false,
_read: [Function],
fieldname: 'homework',
filename: '2017-1-18.json',
encoding: '7bit',
transferEncoding: '7bit',
mime: 'application/octet-stream',
mimeType: 'application/octet-stream' }
At that time, I saw an attribute called buffer, and I also tried the Buffer module in node, but it didn't seem to work.
In short, the question is how to convert the file stream to blob format?
Please give me some guidance
Decided not to store the files in the database
MongoDB does not
blob
格式,你需要的是GridFS
. Take a look at the driver documentation first, there are examples in it. If there is anything you don’t understand, discuss it later.https://mongodb.github.io/nod...