我在流星file picker plus package FileCRicker選擇後輸出圖像有點麻煩。如何抓取上傳的圖片url或文件路徑,以便將其傳遞到表單輸入並將其放入集合中。加入收藏並不是我擔心的一個問題,那就是我無法獲得歡呼的麻煩。流星和filepicker加包
所有包含在postSubmit模板中。
我有
<input type="filepicker" name="myName" />
一種形式,在相同的模板
<img src="{{filepickerIdToUrl myName}}">
一個IMG輸出和路由器文件方含
Router.onBeforeAction(function(){
loadFilePicker('magickey');
//can leave out key if its in settings
this.next();
},{only:['postSubmit']});
這裏是全postSubmit模板
<template name="postSubmit">
<form>
<label for="title">Title</label>
<input name="title" id="title" type="text" value="" placeholder="Name your post"/>
<button id="uploadImage" class="btn btn-info btn-sm"><i class="fa fa-upload"></i> Upload</button>
<input type="submit" value="Submit"/>
</form>
<img id="imagePreview" class="img-responsive" src="{{filepickerIdToImageUrl imageId placehold_it='500x350' h=200 w=300}}"/>
<button id="removeImage" class="btn btn-warning btn-sm"><i class="fa fa-trash-o"></i> Remove</button>
這也是我postSubmit事件
Template.postSubmit.events({
'submit form': function(e) {
e.preventDefault();
var post = {
title: $(e.target).find('[name=title]').val(),
image: $(e.target).find('[name=image]').val()
};
Meteor.call('postInsert', post, function(error, result) {
// display the error to the user and abort
if (error)
return alert(error.reason);
Router.go('postPage', {_id: result._id});
});
}
});
這是我的包!你能發佈更多的代碼來更清楚你在做什麼嗎? – 2014-11-08 23:23:10
@ nate-strauser我已添加完整的postSubmit代碼。我希望圖像在從文件選擇器中選擇後顯示在頁面上。最終我會將網址傳遞到隱藏字段並提交帖子,但現在,我只想查看錶單模板頁面上選擇的圖像頁面/ – 2014-11-09 17:20:03
我是否需要執行meteor.settings部分? – 2014-11-09 17:44:11