3

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.

4

2 回答 2

6

Node.JS 不会自动将上传的文件保存到磁盘。相反,您必须通过请求和事件multipart/form-data自己阅读和解析内容。dataend

或者,您可以使用库来为您完成所有这些工作,例如connect/express为其bodyParsermultipart中间件(完整示例):

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...
});

或者formidable直接connect使用,用于multipart中间件(完整示例)。

并且,对于// copy...评论,请参阅如何复制文件?.

于 2012-09-15T04:17:41.153 回答
-2
app.post('/', function(req, res, next){
    var file_name=req.file.filename;
    var file_path=req.file.path;
}
于 2019-11-30T06:25:06.320 回答