0
你好,我是流星新人,尝试开发一个简单的文件/图片上传/下载。流星无法上传图片
我的代码和包:
meteor create testApp
meteor add cfs:standard-packages
meteor add cfs:filesystem
testApp.js:
YourFileCollection = new FS.Collection("yourFileCollection", {
stores: [new FS.Store.FileSystem("yourFileCollection", {path: "~/meteor_uploads"})]
});
if (Meteor.isClient) {
// counter starts at 0
Template.yourTemplate.events({
'change .your-upload-class': function(event, template) {
FS.Utility.eachFile(event, function(file) {
var yourFile = new FS.File(file);
yourFile.creatorId = Meteor.userId(); // add custom data
YourFileCollection.insert(yourFile, function (err, fileObj) {
if (!err) {
// do callback stuff
}
});
});
}
});
}
if (Meteor.isServer) {
YourFileCollection.allow({
insert: function (userId, doc) {
return !!userId;
},
update: function (userId, doc) {
return doc.creatorId == userId
},
download: function (userId, doc) {
return doc.creatorId == userId
}
});
}
和HTML:
<head>
<title>protoSonn</title>
</head>
<body>
<h1>Welcome to Meteor!</h1>
{{> yourTemplate}}
</body>
<template name="yourTemplate">
<input class="your-upload-class" type="file">
</template>
在我的/ testApp /公用文件夹也两幅图像。 在我的公用文件夹中选择一个图像后,单击确定。没有事情发生。在MongoDB中没有创建任何集合。怎么了?