0

我使用 collectionfs 在我的应用程序中存储文件。

我将随 collectionfs 提供的大部分自述代码复制并粘贴到我的应用程序中,并添加了

{{cfsFileUrl "default1"}}

到我的文件列表。一切都在我的本地机器上运行。

当我部署到 ???.meteor.com 时出现问题

mrt deploy ???.meteor.com

我可以上传和下载图片,还可以从 cfsFileUrl 显示一个 url,

但:

当我访问该网址时,我收到错误 404。

我的代码:client.html

<body>
    {{loginButtons}}
    {{>queueControl}}
    <br>ta
    <br>
    {{>fileTable}}
</body>

<template name="queueControl">
    <h3>Select file(s) to upload:</h3>
    <input name="files" type="file" class="fileUploader" multiple>
</template>

<template name="fileTable">
    {{#each files}}
    {{cfsDownloadButton "ContactsFS" class="btn btn-primary btn-mini" content=filename}}<br>
        <img src="{{cfsFileUrl "default1"}}">
    {{/each}}
</template>

客户端.js

ContactsFS = new CollectionFS('contacts', { autopublish: false });

Deps.autorun(function () {
    Meteor.subscribe('myContactsFiles');
});

Template.queueControl.events({
    'change .fileUploader': function (e) {
        var files = e.target.files;
        for (var i = 0, f; f = files[i]; i++) {
            ContactsFS.storeFile(f);
        }
    }
});

Template.fileTable.files = function() {
    //show all files that have been published to the client, with most recently uploaded first
    return ContactsFS.find({}, { sort: { uploadDate:-1 } });
};

服务器.js

ContactsFS = new CollectionFS('contacts', { autopublish: false });

Meteor.publish('myContactsFiles', function() {
    if (this.userId) {
        return ContactsFS.find({ owner: this.userId }, { limit: 30 });
    }
});

ContactsFS.allow({
    insert: function(userId, file) { return userId && file.owner === userId; }
});

ContactsFS.fileHandlers({
  default1: function(options) { // Options contains blob and fileRecord — same is expected in return if should be saved on filesytem, can be modified
    console.log('I am handling default1: ' + options.fileRecord.filename);
     console.log(options.destination());
    return { blob: options.blob, fileRecord: options.fileRecord }; // if no blob then save result in fileHandle (added createdAt)
  }
});
4

1 回答 1

0

我遇到了类似的问题,并将其发布在 collectionfs 问题页面上。看看:https ://github.com/CollectionFS/Meteor-CollectionFS/issues/85

于 2014-01-06T23:52:29.453 回答