Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 第一个请求返回503刚刚上传到Meteor GridFS的图像_Javascript_Meteor_Gridfs - Fatal编程技术网

Javascript 第一个请求返回503刚刚上传到Meteor GridFS的图像

Javascript 第一个请求返回503刚刚上传到Meteor GridFS的图像,javascript,meteor,gridfs,Javascript,Meteor,Gridfs,有人能告诉我为什么会发生这种错误以及如何解决它吗? 当我重新加载页面(cmd+r)时,图像请求工作正常 来自浏览器控制台的错误: <template name="profileedit"> <img src="{{imgsrc}}" style="width:400px" > </template> 503(服务不可用) 发生了什么: <template name="profileedit"> <img src="{{imgsrc}

有人能告诉我为什么会发生这种错误以及如何解决它吗? 当我重新加载页面(cmd+r)时,图像请求工作正常

来自浏览器控制台的错误:

<template name="profileedit">
  <img src="{{imgsrc}}" style="width:400px" >
</template>
503(服务不可用)

发生了什么:

<template name="profileedit">
  <img src="{{imgsrc}}" style="width:400px" >
</template>
  • 图像已上载(gridFS)
  • url已添加到用户配置文件中
  • img src=“{imgsrc}}”被反应性更新,因此是http请求
  • 请求url正确,但结果为503
  • 重新加载页面,错误就会消失
  • 上传图像的代码

    Template.profileedit.events({
    'change .myFileInput': function(event, template) {
    var files = event.target.files;
    
    for (var i = 0, ln = files.length; i < ln; i++) {
      Images.insert(files[i], function (err, fileObj) {
    
    
          var userId = Meteor.userId();
          var imagesURL = {
            "profile.image": "/cfs/files/images2/" + fileObj._id
    
          };
          Meteor.users.update(userId, {$set: imagesURL});
    
    
      });
    
    
    }
    
    
    }
    
    显示图像的HTML:

    <template name="profileedit">
      <img src="{{imgsrc}}" style="width:400px" >
    </template>
    
    
    
    其他东西

    这个问题在本地和meteor.com上都是一样的 不安全且自动发布处于活动状态(这只是学习步骤)

    谢谢
    Jesper

    我可以想象您遇到了一个问题,Mongo还没有准备好检索对象。我的猜测是,反应式更新发生在您的图像实际可供检索之前,但当您点击“刷新”按钮时,它已经存在并准备好被检索,这就是为什么这种变通方法可以工作的原因


    有几种方法可以解决这个问题。例如:基本上允许您设置一个“等待”图像,该图像将在您的文件未准备好时显示,并在您的图像设置为要检索时进行反应性更新。您也可以通过显示的实现自行完成此操作。

    还有其他更好的方法来解决此问题吗?当图像准备就绪并调用页面渲染时是否有回调?