-
Notifications
You must be signed in to change notification settings - Fork 21
/
express.coffee
67 lines (56 loc) · 1.57 KB
/
express.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
papercut = require('../')
path = require('path')
papercut.configure ->
papercut.set('storage', 'file')
papercut.set('directory', path.join(__dirname, '/../images/output'))
papercut.set('url', '/output')
papercut.set('process', 'crop')
papercut.configure 'production', ->
papercut.set('storage', 's3')
papercut.set('bucket', 'papercut')
papercut.set('S3_KEY', process.env.S3_KEY)
papercut.set('S3_SECRET', process.env.S3_SECRET)
AvatarUploader = papercut.Schema (schema)->
@version
name: 'thumbnail'
size: '45x45'
@version
name: 'avatar'
size: '200x200'
express = require('express')
app = express()
app.use express.static( path.join(__dirname, '/../images/'))
app.use express.bodyParser()
app.get '/', (req, res)->
res.send 200, """
<html>
<head>
<title>Papercut Example</title>
</head>
<body>
<h1> Papercut! </h1>
<form action='/avatar' method='post' enctype="multipart/form-data">
<input type='file' name='avatar'/>
<button>Upload</button>
</form>
</body>
</html>
"""
imageId = 0
app.post '/avatar', (req, res)->
uploader = new AvatarUploader()
uploader.process "#{imageId++}", req.files.avatar.path, (err, images)->
res.send 200, """
<html>
<head>
<title>Papercut Example: Result</title>
<body>
<h1> Papercut! </h1>
<img src='#{images.thumbnail}'/>
<img src='#{images.avatar}'/>
</body>
</head>
</html>
"""
console.log 'express listening port 3000...'
app.listen 3000