Skip to content

Instantly share code, notes, and snippets.

@onepixelsolid
Created November 12, 2014 14:10
Show Gist options
  • Save onepixelsolid/3890f7e1be1a76d316a5 to your computer and use it in GitHub Desktop.
Save onepixelsolid/3890f7e1be1a76d316a5 to your computer and use it in GitHub Desktop.
Meteor - S3 file upload + thumbnailing
#
# FS Collection
#
profileThumbsStore = new FS.Store.S3('thumb',
accessKeyId : 'XXXXXXXXXXXXXXXXXX'
secretAccessKey : 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
bucket : 'my-bucket-name'
folder : 'thumb'
transformWrite : (fileObj, readStream, writeStream) ->
gm(readStream, fileObj.name()).resize("100", "100").stream().pipe writeStream
return
)
profileStore = new FS.Store.S3('original',
accessKeyId : 'XXXXXXXXXXXXXXXXXX'
secretAccessKey : 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
bucket : 'my-bucket-name'
folder : 'original'
)
@Images = new FS.Collection('profiles',
stores: [profileStore, profileThumbsStore]
)
#
# Template Events
#
Template.my_template.events
'change .profile-image': (event, template) ->
files = event.target.files
i = 0
ln = files.length
while i < ln
Images.insert files[i], (err, fileObj) ->
console.log fileObj
i++
return
<template name="my_template">
<input type="file" class="profile-image">
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment