I use Autoform and Slingshot for my S3 interaction. When the user submits the form, I want to intercept the process, upload the file to S3 via Slingshot, expand the doc object with the return downloadUrl , and then at that moment return a new updated document and continue the autoform process
I have the following code:
{{#autoForm collection="Tabs" id="newTabForm" type="method" meteormethod="createTab"}} ... <div class="modal-body"> <fieldset> {{> afFormGroup name='downloadUrl' type='file' class='file-bag'}} ... AutoForm.hooks({ newTabForm: { before: { insert: function(doc, template) { console.log(doc); var file = $('.file-bag')[0].files[0]; var self = this; uploader.send(file, function(error, downloadUrl) { if (error) { throw new Meteor.Error(error); } doc = _.extend(doc, { downloadUrl: downloadUrl }); self.result(doc); }); } }, .... Meteor.methods({ createTab: function(doc) { check(doc, TabSchema); var priceInCents = doc.price * 100; var extraTabAttributes = { userId: Meteor.userId(), price: priceInCents }; _.extend(doc, extraTabAttributes); Tabs.insert(doc, function(error, result) { if (error) { return error; } }); }
Which correctly stores the url (however it looks strange, C: // fakepath / filename ..) in the document, but it is not possible to upload it to the S3 server
Also a side question is why console.log(doc); in the list before it intercepts something on the client / server?
source share