Skip to content

Instantly share code, notes, and snippets.

@easylogic
Created April 4, 2011 00:46
Show Gist options
  • Save easylogic/900983 to your computer and use it in GitHub Desktop.
Save easylogic/900983 to your computer and use it in GitHub Desktop.
implements file upload in zappa
it is so simple.
it is that add connect-form in zappa
1. npm install zappa
2. npm install connect-form
3. cd /usr/local/lib/node/.npm/zappa/active/package/lib - move yourself npm directory
4. edit zappa.coffee
zappa = exports
express = require 'express'
form = require 'connect-form' <--- append connect-form module
fs = require 'fs'
puts = console.log
5. set http server
@http_server.use express.bodyParser()
@http_server.use express.cookieParser()
@http_server.use express.session(secret: 'hackme' )
@http_server.use form(keepExtensions: true) <-------- append connect-form middleware
6. coffee -c zappa.coffee
it is done to implements file-upload in zappa
7. use connect-form in zappa
post '/': ->
request.form.complete (err, fields, files) ->
if not err
// saveGridFS file.filename for filekey, file of files
next()
else
next()
request.form.on 'progress', (bytesReceived, bytesExpected) ->
percent = (bytesReceived / bytesExpected * 100) | 0
process.stdout.write 'Uploading: %' + percent + "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment