如何在 Meteor 启动时上传图像到服务器

How to Upload an Image to Server on Meteor Startup

我正在尝试为未 have/not 上传图片的用户设置默认 DP。

尝试使用帮助程序显示内容但出现错误"Uncaught Error: {{#each}} currently only accepts arrays, cursors or falsey values." 下面的代码(客户端 JS) JS :

Template.mcomments.helpers({
    'mcommentsdata':function(){
      return comdata.find({},{sort:{"at":-1}}).fetch();
    },

    images2: function () {
        var fetchimg=Meteor.users.findOne({
            "_id":this.__id
          });

        if((fetchimg.profileimage==undefined)||(fetchimg.profileimage=="")){
        var hello="/images/prof.jpg"
        return hello;
        }else{
            return Images.find({"_id":fetchimg.profileimage})


        }
    }
  });

HTML

    <template name="mcomments">
<div id="mcomments" class="col-lg-3">
    <div><h5 class="mcommentsheader">Followup Stream </h5>
    </div>
    <div class="col-lg-12 scrolling comscrolllist" id="mcomments1">
        <div id="mcomments2">
            {{#each mcommentsdata}}
            <div class="col-lg-12 comcontainer">
                <div class="row">
                    <div class="col-lg-3 indcomments" >
                        {{#each images2}}
                        <img src="{{this.url
                        }}" width="45px" height="50px" alt="">
                        {{/each}}
                    </div>
                    <div class="col-lg-9" style="">
                        <div class="row combody" >
                            <div class="pull-left mcommfont" >{{user}}</div>
                            <div class="pull-right mcommcust">{{product}} Case#{{productcaseno}}</div>
                        </div>
                        <div class="maincomment">{{comment}}</div>
                        <div class="comtemp"> <span data-livestamp="{{at}}"></span></div>
                    </div>
                </div>
            </div>

            <div class="col-lg-12 comblankspace">
            </div>
            {{/each}}
        </div>
    </div>
</div>
</template>

现在我已经放弃了这种方法并考虑上传图像并默认将 url 附加到所有配置文件 (onCreateuser) 直到它们更改 it.I 相信这样做我可能有在服务器启动时自动上传和图像。请引导我走向正确的方向,因为我仍然是流星的菜鸟。

存储适配器:GridFS。

此致, 阿扎鲁丁

将 'hello' 变量更改为以下代码:

var hello = [
    { url: "/images/prof.jpg" }
];

您 运行 遇到了问题,因为 hello 当前是一个字符串 - #each 需要一个 array/cursor/etc。正如你的错误所暗示的那样。

或者,您可以在每个块上使用 {{#else}} 并完全避免返回您的 'hello' 案例:

{{#each images}}
    ...
{{else}}
    <!-- Default profile image code -->
{{/each}}