Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ind.ie Projects
iamindie-node
Commits
e7d2a495
Commit
e7d2a495
authored
Oct 14, 2014
by
Aral Balkan
Browse files
Video uploads now working.
parent
b87d3dd3
Changes
3
Hide whitespace changes
Inline
Side-by-side
.gitignore
0 → 100644
View file @
e7d2a495
node_modules/
videos/
\ No newline at end of file
index.coffee
0 → 100644
View file @
e7d2a495
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
package.json
View file @
e7d2a495
...
...
@@ -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
"
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment