Skip to content

Instantly share code, notes, and snippets.

@flowck
Created October 27, 2016 20:08
Show Gist options
  • Save flowck/a4f66ed45ba9fea419597c8d81a5500a to your computer and use it in GitHub Desktop.
Save flowck/a4f66ed45ba9fea419597c8d81a5500a to your computer and use it in GitHub Desktop.
File Upload works with http but not with https
var fs = require('fs'),
https = require('https'),
express = require('express'),
app = express(),
multer = require('multer');
var storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, '/tmp/');
},
filename: function(req, file, cb) {
cb(null, file.originalname);
}
});
var upload = multer({
storage: storage
});
// Serve static files
app.use(express.static("./"));
// Create a https server
https.createServer({
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
}, app).listen(55555);
app.get('/', function (req, res) {
res.header('Content-type', 'text/html');
return res.end('<h1>Hello, Secure World!</h1>');
});
// Post route
app.post('/upload/file', upload.single("upload"), function(req, res) {
if (req.file) {
res.send("Upload complete");
res.end();
} else {
res.send("No file");
res.end();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment