Commit 8ee8e676 authored by yPhil's avatar yPhil

Prefs: File UL prototype OK

parent e8fd1b1e
......@@ -12,6 +12,8 @@ app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use('/static', express.static(__dirname + '/public'));
app.use('/tmp', express.static(__dirname + '/tmp'));
app.use('/bower', express.static(__dirname + '/bower_components'));
app.use('/', index);
......
......@@ -191,6 +191,15 @@
"resolved": "https://registry.npmjs.org/bower/-/bower-1.8.2.tgz",
"integrity": "sha1-rfU1KcjUrwLvJPuNU0HBQZ0z4vc="
},
"busboy": {
"version": "0.2.14",
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.14.tgz",
"integrity": "sha1-bCpiLvz0fFe7vh4qnDetNseSVFM=",
"requires": {
"dicer": "0.2.5",
"readable-stream": "1.1.14"
}
},
"bytes": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
......@@ -433,6 +442,15 @@
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
},
"dicer": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/dicer/-/dicer-0.2.5.tgz",
"integrity": "sha1-WZbAhrszIYyBLAkL3cCc0S+stw8=",
"requires": {
"readable-stream": "1.1.14",
"streamsearch": "0.1.2"
}
},
"dom-serializer": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.0.1.tgz",
......@@ -621,6 +639,16 @@
}
}
},
"express-fileupload": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/express-fileupload/-/express-fileupload-0.3.0.tgz",
"integrity": "sha512-IdX2oOFphEg3px0NylgtqluSTjDZgAyEfhZBWgmDNw75xbG89UnYqi/ZbFsTuDh1RGDDUK4JqdHYNH4p2KK1+g==",
"requires": {
"busboy": "0.2.14",
"fs-extra": "4.0.2",
"streamifier": "0.1.1"
}
},
"extend": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz",
......@@ -712,6 +740,16 @@
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
"integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
},
"fs-extra": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.2.tgz",
"integrity": "sha1-+RcExT0bRh+JNFKwwwfZmXZHq2s=",
"requires": {
"graceful-fs": "4.1.11",
"jsonfile": "4.0.0",
"universalify": "0.1.1"
}
},
"getpass": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz",
......@@ -720,6 +758,11 @@
"assert-plus": "1.0.0"
}
},
"graceful-fs": {
"version": "4.1.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz",
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg="
},
"handlebars": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.5.tgz",
......@@ -985,6 +1028,14 @@
"resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz",
"integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus="
},
"jsonfile": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
"requires": {
"graceful-fs": "4.1.11"
}
},
"jsonify": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz",
......@@ -1416,6 +1467,16 @@
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz",
"integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4="
},
"streamifier": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/streamifier/-/streamifier-0.1.1.tgz",
"integrity": "sha1-l+mNj6TRBdYqJpHR3AfoINuN/E8="
},
"streamsearch": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
"integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
......@@ -1577,6 +1638,11 @@
"xregexp": "2.0.0"
}
},
"universalify": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.1.tgz",
"integrity": "sha1-+nG63UQ3r0wUiEHjs7Fl+enlkLc="
},
"unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
......
......@@ -2,11 +2,18 @@ var express = require('express');
var router = express.Router();
var favicon = require('favicon');
var parser = require('rss-parser');
const fileUpload = require('express-fileupload');
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
router.use(fileUpload({
limits: { fileSize: 50 },
safeFileNames: true,
preserveExtension: true
}));
router.get('/feedicon', function(req, res, next) {
favicon(req.query.url, function(err, u) {
......@@ -40,4 +47,20 @@ router.get('/feed', function(req, res, next) {
});
});
router.post('/upload', function(req, res) {
if (!req.files)
return res.status(400).send('No files were uploaded.');
// The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
let sampleFile = req.files.sampleFile;
// Use the mv() method to place the file somewhere on your server
sampleFile.mv('/tmp/plop.json', function(err) {
if (err)
return res.status(500).send(err);
res.send('File uploaded!');
});
});
module.exports = router;
......@@ -254,20 +254,6 @@
// $('#jsonUpload').fileUpload();
$('#jsonUpload').fileUpload({
uploadData : { 'extra_data' : 'blah' }, // Append POST data to the upload
submitData : { 'moar_extra_data' : 'blah' }, // Append POST data to the form submit
uploadOptions : { dataType : 'json' }, // Customise the parameters passed to the $.ajax() call on uploads. You can use any of the normal $.ajax() params
submitOptions : { dataType : 'json' }, // Customise the parameters passed to the $.ajax() call on the form submit. You can use any of the normal $.ajax() params
before : function(){
console.log('plop!')
}, // Run stuff before the upload happens
beforeSubmit : function(uploadData){ console.log(uploadData); return true; }, // access the data returned by the upload return false to stop the submit ajax call
success : function(data, textStatus, jqXHR){ console.log(data); }, // Callback for the submit success ajax call
error : function(jqXHR, textStatus, errorThrown){ console.log(jqXHR); }, // Callback if an error happens with your upload call or the submit call
complete : function(jqXHR, textStatus){ console.log(jqXHR); } // Callback on completion
});
});
function myFunction(){
......@@ -286,18 +272,22 @@
if ('size' in file) {
txt += "size: " + file.size + " bytes <br>";
}
if ('content' in file) {
txt += "content: " + file.content + " <br>";
}
}
}
}
else {
if (x.value == "") {
txt += "Select one or more files.";
txt += "Select one file.";
} else {
txt += "The files property is not supported by your browser!";
txt += "<br>The path of the selected file: " + x.value; // If the browser does not support the files property, it will return the path of the selected file instead.
}
}
document.getElementById("demo").innerHTML = txt;
$("#demo").html(txt);
}
</script>
......@@ -363,8 +353,18 @@
<fieldset class="prefsForm ui-widget ui-widget-content">
<input type="file" id="myFile" size="50" onchange="myFunction()">
<p id="demo"></p>
<!-- <input type="file" id="myFile" size="50" onchange="myFunction()"> -->
<!-- <p id="demo"></p>
-->
<form ref='uploadForm'
id='uploadForm'
action='http://maw:3000/upload'
method='post'
encType="multipart/form-data">
<input type="file" name="sampleFile" />
<input type='submit' value='Upload!' />
</form>
<!-- <progress></progress> -->
<!--
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment