Reputation: 1345
Following code for the template:
<form>
<input type="text" name="title" placeholder="Title" />
<input type="file" id="file" accept="image/*" />
<input type="submit" value="Upload" />
</form>
And then in my events for that template:
'submit form': function (event, template)
{
event.preventDefault();
var file = event.target.files;
var title = event.target.title.value;
var image = Images.insert(file[0], function (err, fileObj)
{
});
Bla.insert({name: title, userId: '123123', image: image._id});
}
Now I am getting the error: Uncaught TypeError: Cannot read property '0' of undefined
So event.target.files
is undefined, but I don't get why.
When I just use the file input and then a change event handler on that + jQuery get to get the file, it works.
Upvotes: 1
Views: 7555
Reputation: 1542
Try to console.log
your event and you'll get the location of your files where it's stored in the event. it'll be similar like this
event.target.[name-of-field].files
Upvotes: 4