Commit e7d2a495 authored by Aral Balkan's avatar Aral Balkan
Browse files

Video uploads now working.

parent b87d3dd3
node_modules/
videos/
\ No newline at end of file
express = require 'express'
multer = require 'multer'
fs = require 'fs'
moment = require 'moment'
app = express()
app.all '*', (req, res, next) ->
# Cross-Origin Resource Sharing (CORS) — courtesy http://enable-cors.org/server_expressjs.html
res.header "Access-Control-Allow-Origin", "*"
res.header "Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"
next()
app.use multer {
dest: './videos/'
limits:
files: 1,
fileSize: 50000000 # 50MB
rename: (fieldname, filename) ->
return (fieldname + '-' + moment().format().replace(/:/g, '_').replace(/\+/g, '_').replace(/-/g, '_') + '-' + filename).toLowerCase()
onFileUploadStart: (file) ->
console.log file.fieldname + ' is about to start uploading…'
console.log file
# Do some security checks.
fieldnameIsWrong = (file.fieldname != 'video-message')
mimetypeIsWrong = (/^video.*/.test(file.mimetype) == false)
if fieldnameIsWrong or mimetypeIsWrong
console.log 'File failed security checks. Not uploading.'
return false
}
app.post '/upload', (request, response) ->
console.log 'POST /upload called.'
# console.dir(request.files)
# console.log request.files['video-message']['size']
server = app.listen 3000, ->
console.log "Listening on port %d", server.address().port
\ No newline at end of file
......@@ -7,5 +7,11 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Aral Balkan",
"license": "GPL-3.0"
"license": "GPL-3.0",
"dependencies": {
"connect-busboy": "0.0.2",
"express": "^4.9.7",
"moment": "^2.8.3",
"multer": "^0.1.6"
}
}
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