我正在使用FS.Collection上传服务器上的短视频文件,然后将其作为附件发送到电子邮件中。
插入到服务器上的集合可以工作,我可以访问客户端上的集合项目,还可以使用指向文件Url - localhost:3000/cfs/files/videos/{{item_id}}的路径直接流式传输它。
我想知道如何访问服务器上的集合。我想发送以下形式的附件电子邮件,并需要访问服务器上的文件路径和文件名。我试着这样做:
Email.send({
to: to,
from: from,
subject: subject,
text: text,
attachments:[{fileName:"video.mp4", filePath:"/cfs/files/videos/{{item_id}}"}]
});它在电子邮件中显示了附件视频播放器,但有一条错误消息,所以我假设我没有正确访问文件。
我的Collection.js很简单:
var videoStore = new FS.Store.GridFS("videos");
Videos = new FS.Collection("videos", {
stores: [videoStore]
});发布于 2016-02-19 20:27:27
您不能通过collectionFS的filePath使用附件。" /cfs/ files /videos /{{item_id}}“为虚拟路径,即/cfs/files/videos中不存在文件,也没有文件夹'/cfs/files/videos‘。
您可以改用http路径:
var ROOT_URL = process.env.ROOT_URL;
var rootUrl;
if (ROOT_URL.indexOf('/', ROOT_URL.length - 1) != -1) {
rootUrl = ROOT_URL.substring(0, ROOT_URL.length - 1);
} else {
rootUrl = ROOT_URL;
}
var attachments = [];
attachment = {
fileName: fileName(url),
filePath: rootUrl + "/cfs/files/videos/{{item_id}}"
};
attachments.push(attachment);
Email.send({
to: to,
from: from,
subject: subject,
text: text,
attachments: attachments
});https://stackoverflow.com/questions/35416628
复制相似问题