'How to get the name of the file uploaded?
I made a research and found only forms and formidable
tutorials. However, I couldn't find how to get the original file name.
I am using Postman to send a file to http://localhost:8081/file
. The file is sent in binary as body. The file sent is xxx.json
.
In Node I created an HTTP server:
const http = require("http");
const fs = require("fs");
const server = http.createServer(async (req, res) => {
if (req.method === "POST" && req.url === "/file") {
req.on("data", (chunk) => {
console.log(`Data chunk available: ${chunk}`);
// fs.createWriteStream("./finalFolder");
});
}
res.end();
});
I want to save the file to /finalFolder
preserving the original filename xxx.json
.
Where do I get the name of the file uploaded?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|