【发布时间】:2013-08-26 16:17:00
【问题描述】:
我正在尝试制作一个能够使用 express 保存文件的简单文件服务器:
var app = express();
app.use(express.bodyParser({uploadDir:'./uploads'}))
app.post('/upload', function(req, res, next) {
console.log("Uploading File");
req.on('data', function(raw) {
console.log('received data: ' + raw);
});
req.on('end', function() {
console.log('File uploaded');
res.send(200);
});
});
我在“上传”文件夹中只得到一个空文件。
我错过了什么?
也许这是一个非常愚蠢的问题,但我是 node.js 的新手。
编辑:更多信息...
我是从我的客户那里发送的:
POST /upload HTTP/1.1
Connection: Close
Content-Length: 42
Content-Type: multipart/form-data; boundary="MIME_boundary_572B1A2B457D3267"
Cookie: session.id=b268b12e-0c05-11e3-8702-7a7919510927
Host: localhost:8080
Transfer-Encoding: chunked
Client 3 Received Message: E4
--MIME_boundary_572B1A2B457D3267
Content-Disposition: form-data; name="test1.txt"; filename="test1.txt"
Content-Type: application/octet-stream
File1 from client in W7 to send to server.
--MIME_boundary_572B1A2B457D3267--
0
分两块。
【问题讨论】:
-
我读过,不适合我。
标签: node.js file-upload express