Babak Abadkheir
Babak Abadkheir

Reputation: 2348

read content from request.files _ nodejs

I need to read the content of txt file or CSV file that user uploads from form-data.

so I know I can save the file in an upload directory and then read it from storage. but I need to know is there any way I can read from request, without saving it in local storage? I also I checked my file has some property like this:

{
  name: 'emals.txt',
  data: <Buffer 27 61 6c 69 40 67 2e 63 6f 6d 27>,
  size: 11,
  encoding: '7bit',
  tempFilePath: '',
  truncated: false,
  mimetype: 'text/plain',
  md5: '09c3de70dcf2d0f0ec6fcb79ed147c4a',
  mv: [Function: mv]
}

as we see we have data its Buffer . is there any way I could use this buffer on the fly?

Upvotes: 0

Views: 503

Answers (1)

kailash tallapragada
kailash tallapragada

Reputation: 36

You could try converting the buffer into a node.js string using

buffer.toString(encoding);

Use encoding parameter ascii to get the string from a 7-bit encoded file. In your case, the buffer is stored in the data property of the object.

Upvotes: 1

Related Questions