我正在尝试使用流星中的CollectionFS创建一个图像集合。我使用了来自https://github.com/CollectionFS/Meteor-CollectionFS/wiki/Insert-One-File-From-a-Remote-URL的以下代码
var url='data/2.jpg';
var newFile = new FS.File();
newFile.attachData(url, function (error) {
if (error) throw error;
newFile.name("testImage.jpg");
Images.insert(newFile, function (error, fileObj) {});
}); 上面的代码是在'js/server.js‘文件中的启动函数中编写的&它所指的图像是'js/data/2.jpg’。
但是它似乎不起作用&抛出这个错误:
Error: ENOENT, stat 'C:\Users\[username]\WebstormProjects\test\.meteor\local\build\programs\server\data\2.jpg'发布于 2015-11-16 17:20:03
error ENOENT是“Error NO ENTry”的缩写。您收到此错误是因为文件2.jpg无法访问,或者在目录C:\Users\[username]\WebstormProjects\test\.meteor\local\build\programs\server\data\中不存在。
如果要从远程URL插入文件,则需要提供可访问的URL,例如:
Images = new FS.Collection("images", {
stores: [new FS.Store.FileSystem("images", {path: "~/uploads"})]
});
if (Meteor.isServer) {
Meteor.startup(function () {
var url = 'http://www.panderson.me/images/lena.jpg';
var newFile = new FS.File();
newFile.attachData(url, function (error) {
if (error) throw error;
newFile.name("lena.jpg");
Images.insert(newFile, function (error, fileObj) {
console.log(error);
console.log(fileObj);
});
});
});
}我假设您不想从远程URL插入文件。如果是这样的话,将文件放在private目录中,并将变量url更改为:"assets/app/lena.jpg"。
Images = new FS.Collection("images", {
stores: [new FS.Store.FileSystem("images", {path: "~/uploads"})]
});
if (Meteor.isServer) {
Meteor.startup(function () {
var url = "assets/app/lena.jpg";
var newFile = new FS.File();
newFile.attachData(url, function (error) {
if (error) throw error;
newFile.name("lena.jpg");
Images.insert(newFile, function (error, fileObj) {
console.log(error);
console.log(fileObj);
});
});
});
}
https://stackoverflow.com/questions/33734556
复制相似问题