Created
October 27, 2016 20:08
-
-
Save firminochangani/a4f66ed45ba9fea419597c8d81a5500a to your computer and use it in GitHub Desktop.
File Upload works with http but not with https
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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