-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStoreFile.js
More file actions
39 lines (36 loc) · 1022 Bytes
/
StoreFile.js
File metadata and controls
39 lines (36 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var formidable = require('formidable');
var http=require('http');
var fs=require('fs');
http.createServer(function(request, response) {
var rm = request.method.toLowerCase();
var callback="";
var filename="";
if(request.url === '/upload' && rm === 'post') {
var form = new formidable.IncomingForm();
form.uploadDir = process.cwd();
var resp = "";
form
.on("file", function(field, File) {
var date=new Date().getTime();
var newName=process.cwd()+"/tmp/"+File.name;
filename=newName;
fs.renameSync(File.path,newName);
})
.on("field", function(field, value) {
if(field=="callback"){
callback=value;
}
})
.on("end", function() {
resp+='<meta http-equiv="refresh" content="0; url='
resp+=callback;
resp+="?filename=";
resp+=filename;
resp+='">"';
response.writeHead(200, {'content-type': 'text/html'});
response.end(resp);
})
.parse(request);
return;
}
}).listen(7999);