Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
file upload in meteor
Meteor.saveFile = (file)->
fileReader = new FileReader()
fileReader.onload = (blob) ->
Meteor.call 'saveFile',
file:file
blob:blob.srcElement.result
fileReader.readAsBinaryString file
return
# event for upload
_.extend Tempalte.something,
events:
'change input[name=attach]': (e)->
_.each e.srcElement.files, (file) ->
Meteor.saveFile file
app=__meteor_bootstrap__.app
fs=__meteor_bootstrap__.require 'fs'
app.stack.unshift
route: '',
handle: (req, res, next)->
unless /upload\/\/*/gi.test req.url
next()
else
Fiber(->
res.write fs.readFileSync("#{process.cwd()}/server/tests/upload/images/#{req.url.replace('/upload/','')}")
res.end()
).run()
Meteor.methods
saveFile: (param)->
if param.file.type.indexOf('image')+1
Fiber(->
fs.writeFileSync "#{process.cwd()}/server/tests/upload/images/#{param.file.name}",param.blob,'binary'
).run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment