I am using Autoform and Slingshot for my S3 interaction. When the user submits the form, i want to intercept the process, upload the file to S3 through Slingshot, extend the doc
object with the returned downloadUrl
and then at that point, return the new updated doc, 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 url (however looks weird, C://fakepath/filename..) on the document, but fails to upload it to the S3 server
Also side question, why doesnt the console.log(doc);
in the before hooks log anything to the client/server?