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.
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.
Share Improve this question asked Jan 15, 2016 at 13:36 Frederik WitteFrederik Witte 1,3852 gold badges16 silver badges37 bronze badges 3-
1
console.log
your whole event and look through that, you'll find out where your files are stored in the event. – Faysal Ahmed Commented Jan 15, 2016 at 13:48 - Oke I am stupid. I had to do event.target.[name-of-field].files... But shouldn't event.target.files work, too? Thank you. If you make an answer I will accept it – Frederik Witte Commented Jan 15, 2016 at 13:56
- there's no reason of feeling stupid. I apologize to you if my earlier ment made you feel stupid. JQuery event and meteor events are not the same. they do handle things differently. – Faysal Ahmed Commented Jan 15, 2016 at 13:58
1 Answer
Reset to default 4Try 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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745141212a4613438.html
评论列表(0条)