Bogdan Iasinovschi
Bogdan Iasinovschi

Reputation: 21

In ExpressJS, get original filename of a file sent with Body Binary in Postman

My pdf file is being sent to my server as binary data with Postman as seen in the picture attached.

The content of the file is being parsed on my ExpressJS server with req.on((chunk) => ...) etc.

Everything is fine, except the fact that I try to obtain the original filename(highlighted in red - valid-compressed-compressed.pdf) on the server, but I can't find the value anywhere in the request object.

Any suggestions, please?

Upvotes: 1

Views: 1043

Answers (1)

TenorDev
TenorDev

Reputation: 273

Short answer: you cant.

If you look closely at the headers being sent with the request, there are no headers containing the filename. Therefore there are no headers you can access in express to retrieve that information. The only headers you send are Content-Type and Content-Length that gives some information about what you're sending. Other than that there's just the binary request body.

If you want to post a file and the filename you need to look into multipart/form-data (Multer).

Upvotes: 1

Related Questions