Skip to content

Instantly share code, notes, and snippets.

@jacky810124
Last active August 29, 2015 14:20
Show Gist options
  • Save jacky810124/dabda7757cf079207f37 to your computer and use it in GitHub Desktop.
Save jacky810124/dabda7757cf079207f37 to your computer and use it in GitHub Desktop.
Cannot read property 'theFile' of undefined
TypeError: Cannot read property 'theFile' of undefined
at C:\Users\Kang\WebstormProjects\ftpserver\server.js:25:26
at Layer.handle [as handle_request] (C:\Users\Kang\WebstormProjects\ftpserver\node_modules\express\lib\router\layer.js:82:5)
at next (C:\Users\Kang\WebstormProjects\ftpserver\node_modules\express\lib\router\route.js:110:13)
at Route.dispatch (C:\Users\Kang\WebstormProjects\ftpserver\node_modules\express\lib\router\route.js:91:3)
at Layer.handle [as handle_request] (C:\Users\Kang\WebstormProjects\ftpserver\node_modules\express\lib\router\layer.js:82:5)
at C:\Users\Kang\WebstormProjects\ftpserver\node_modules\express\lib\router\index.js:267:22
at Function.proto.process_params (C:\Users\Kang\WebstormProjects\ftpserver\node_modules\express\lib\router\index.js:321:12)
at next (C:\Users\Kang\WebstormProjects\ftpserver\node_modules\express\lib\router\index.js:261:10)
at expressInit (C:\Users\Kang\WebstormProjects\ftpserver\node_modules\express\lib\middleware\init.js:23:5)
at Layer.handle [as handle_request] (C:\Users\Kang\WebstormProjects\ftpserver\node_modules\express\lib\router\layer.js:82:5)
var express = require('express');
var app = express();
var fs = require('fs');
app.get('/', function (req, res) {
res.sendFile(__dirname + '/views/index.html');
});
app.get('/upload', function(req, res){
res.sendFile(__dirname + '/views/upload.html');
});
app.post('/fileUpload', function(req, res){
console.log(req.files.theFile.name);
/*var tmpPath = req.files.uploadingFile.path;
var targetPath = __dirname + '/files/' + req.files.uploadingFile.name;*/
/*fs.rename(tmpPath, targetPath, function(err){
if(err) throw err;
fs.unlink(tmpPath, function(){
res.send('File upload complete');
});
});*/
});
var server = app.listen(80, function () {
});
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Upload</title>
</head>
<body>
<form method="post" enctype="multipart/form-data" action="/fileUpload">
<input type="file" name="theFile">
<input type="submit">
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment