Meteor Upload to AWS S3 -
i have meteor app in insert document (title, description, customer, ...) database. app using autoform, simple schema , collection2. want add possibility upload file s3.
to keep things simple, present filepicker part of 'create document' , once file uploaded, url field (from autoform), should show url of document on s3 (once uploaded) url stored in document collection when create button clicked. realise there might better ways, wanted keep things simple now.
i have tried combine tutorial here. upload s3 works, fail url uploaded file stored documents collection. below screenshot shows layout. idea's?
my current code can found here.
there appear autoform add-on packages address s3 file upload (see "files" section here), since seem using learning opportunity, i'll try explain how i'd using core meteor.
but first, before forget, uploader template child of #autoform
has form
element of it's own. think cause generated html have nested form
elements (which no-no). fix that, i'd move {{/autoform}}
before {{> uploader}}
, add event handler submit button submits form using $('#documentform').submit()
. note: haven't tested that.
now, on actual question. asking how modify in template (the value of url field) event in nested template (the uploader
template). i'd follows:
when instance of parent template created, attach
reactivevar
hold url of uploaded file.template.admindocumentnew.oncreated(function () { this.url = new reactivevar(); });
provide helper reactive var.
template.admindocumentnew.helpers({ url: function () { return template.instance().url; } });
use helper set value in form.
{{> afquickfield name='url' value=url.get}}
pass reactive var uploader template data context:
{{> uploader urlvar=url}}
use reactive var set url when upload finishes (somewhere in upload-to-amazon-s3):
template.data.urlvar.set(url);
i've created a meteorpad demonstrates basic idea outside of context of autoform
, s3.
Comments
Post a Comment