How do I get the name of an uploaded file name/path to manipulate it in node.js? I want move the file from the temp folder to a customer folder.
Node.JS doesn't automatically save uploaded files to disk. You'll instead have to read and parse the multipart/form-data
content yourself via the request's data
and end
events.
Or, you can use a library to do that all for you, such as connect
/express
for its bodyParser
or multipart
middlewares (complete example):
var fs = require('fs');
var express = require('express');
var app = express();
// `bodyParser` includes `multipart`
app.use(express.bodyParser());
app.post('/', function(req, res, next){
// assuming <input type="file" name="upload">
var path = req.files.upload.path;
var name = req.files.upload.name;
// copy...
});
Or use formidable
directly, which connect
uses for the multipart
middleware (complete example).
And, for the // copy...
comment, see How to copy a file?.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With