这是我文件的结构
{ key:
{ originalFilename: 'images.jpg',
path: '/tmp/5323-h7e0e.jpg',
headers:
{ 'content-disposition': 'form-data; name="key"; filename="images.jpg"',
'content-type': 'image/jpeg' },
ws:
{ _writableState: [Object],
writable: true,
domain: null,
_events: [Object],
_maxListeners: 10,
path: '/tmp/5323-h7e0e.jpg',
fd: null,
flags: 'w',
mode: 438,
start: undefined,
pos: undefined,
bytesWritten: 9217,
closed: true,
open: [Function],
_write: [Function],
destroy: [Function],
close: [Function],
destroySoon: [Function],
pipe: [Function],
write: [Function],
end: [Function],
setMaxListeners: [Function],
emit: [Function],
addListener: [Function],
on: [Function],
once: [Function],
removeListener: [Function],
removeAllListeners: [Function],
listeners: [Function] },
size: 9217,
name: 'images.jpg' } }
我尝试了什么 ::
app.js
var express=require('express');
var fs=require('fs');
var http=require('http');
var app=express();
app.set('port',process.env.PORT||7003);
app.use(express.bodyParser());
app.post('/Details/',function(req,res){
var path=req.files.name;
console.log(path);
});
http.createServer(app).listen(app.get('port'),function(){
console.log('Express server listening on port'+app.get('port'));
});
问题 ::我在控制台上显示此undifined
Express server listening on port7003
undefined
Error: Request aborted
at IncomingMessage.<anonymous> (/home/ubuntu/rainmelon/sample_programs/image_express/node_modules/express/node_modules/connect/node_modules/multiparty/index.js:93:17)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at abortIncoming (http.js:1886:11)
at Socket.serverSocketCloseListener (http.js:1898:5)
at Socket.EventEmitter.emit (events.js:117:20)
at TCP.close (net.js:451:12)
image.jpg
?{编辑}
var express=require('express');
var fs=require('fs');
var http=require('http');
var app=express();
app.set('port',process.env.PORT||7003);
app.use(express.bodyParser());
app.post('/Details/',function(req,res){
var originalFilename=req.files.originalFilename;
console.log(originalFilename);
});
http.createServer(app).listen(app.get('port'),function(){
console.log('Express server listening on port'+app.get('port'));
});
这就是我提出请求的方式::
即使在编辑后......我仍然会收到同样的错误
答案 0 :(得分:2)
app.post('/Details/',function(req,res){
var originalFilename = req.files.key.originalFilename;
console.log(originalFilename);
});