Skip to content

Instantly share code, notes, and snippets.

@acidsound
Created May 6, 2014 23:50
Show Gist options
  • Save acidsound/8729aac5e5051967f044 to your computer and use it in GitHub Desktop.
Save acidsound/8729aac5e5051967f044 to your computer and use it in GitHub Desktop.
<template name="basic">
{{#with stuff}}
{{#S3 callback="savedURL"}}
<input type="file">
{{/S3}}
{{/with}}
{{#each savedURL}}
<p>SAVED URL: {{url}}</p>
{{/each}}
</template>
UploadKeys = new Meteor.Collection('uploadKeys');
if (Meteor.isServer) {
Meteor.methods({
save_url: function(url,context){
UploadKeys.insert({
key: context.key,
url: url
});
}
});
}
if (Meteor.isClient) {
Template.basic.rendered = function() {
// 중복 방지용 unique key 생성
Template.basic.setUploadKey();
};
Template.basic.helpers({
"stuff": function() {
return {
key: Session.get('uploadKey')
};
},
"setUploadKey": function() {
Session.set('uploadKey', Meteor.uuid());
},
// 업로드 후 reactive로 URL을 받도록
"savedURL": function() {
var res = UploadKeys.find({
key: Session.get('uploadKey')
});
res.observe({
'added': function(o) {
// URL을 받는 시점에 실행
console.log('uploaded', o.url);
}
});
return res;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment