https://github.com/davebryson/meteor_file_upload_example
上記はMeteor.routerを使用した元のコードです
以前のルーター パッケージではなく、iron-router のみを使用してこのコードを変換したかったのです。
しかし、問題はファイルをアップロードするときです。
Iron-router api を使用してこれらのコードを変換する方法がわかりません。
index.html とサーバー側の main.js コードに問題があると思いますが、修正できません。
以下のコードを Iron Router plz を使って変換していただけませんか?
元のコードのサーバー側 main.js で。
Meteor.Router.configure(
{
bodyParser:
{
uploadDir: 'uploads',
hash: 'sha1',
keepExtensions : true
}
}
);
Meteor.Router.add('/upload/file', 'POST',
function()
{
var title = this.request.body.fileTitle,
size = this.request.files.fileInfo.size,
path = this.request.files.fileInfo.path,
name = this.request.files.fileInfo.name,
obj = {title: title, size: size, path: path, name: name};
Files.insert(obj);
// redirect to root
return [301, {Location: '/'}, ""]
}
);
そして、私はすでに以下のようにクライアント側のmain.jsのコードを変換しました
Router.map(function () {
this.route('listFiles', {path: '/'});
this.route('addFile', {path: '/add'});
});
Template.listFiles.helpers({
list: function () {
return Files.find({});
}
});
Template.listFiles.events({
'click #addFileBtn' : function(e) {
e.preventDefault();
Router.go('/add');
}
});
Template.addFile.events({
'click #cancelBtn': function(e){
e.preventDefault();
Router.go('/');
}
});
Meteor.subscribe("files");
ポイントは、iron-router を使用してサーバーサイド コードで http メソッドを使用する方法を処理できないことです。