CollectionFS 503服务不可用

时间:2016-03-09 13:37:00

标签: meteor collectionfs

我需要在飞行中上传'用户的形象。但我收到错误503服务不可用。

user.js的

Meteor.subscribe('userImages');

Template.userProfil.events({
  'change [name=userPhotoUpload]': function(event) {
    event.preventDefault();
    FS.Utility.eachFile(event, function(file) {
        var newFile = new FS.File(file);
        newFile.metadata = {
            createdBy:Meteor.userId(),
        }
        userImages.insert(newFile, function (err, fileObj) {
            if (err){
             // handle error
            } else {
                // handle success depending what you need to do
                var currentUserId = Meteor.userId();
                var imagesURL = {
                  "profile.userImg": '/cfs/files/userImages/' + fileObj._id + '/' + fileObj.name()
                };
                Meteor.users.update(currentUserId, {$set: imagesURL});//there I get url and

            }
        });
    });

  }
});

router.js

Router.route('/organizer', {
  name: 'userProfil',
  template: 'userProfil',
  data: function() {
      var currentUser = Meteor.userId();
      return Meteor.user({_id: currentUser});
  }
});

用户img.html

<img src="{{profile.userImg}}">
升级图像后,我得到了这个错误:

http://localhost:3000/cfs/files/userImages/wNjvF8uuN8j6fd8md/exampl2.jpg 503 (Service Unavailable)

但是这条路径是绝对正确的,并且在手动重新加载页面之后就可以了。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

好的,我找到了一些解决方案,但我不认为这是正确的方法。也许有人有更好的决定?

更改:

user.js的

'change [name=userPhotoUpload]': function(event) {
    event.preventDefault();
    FS.Utility.eachFile(event, function(file) {
        var newFile = new FS.File(file);
        newFile.metadata = {
            createdBy:Meteor.userId(),
        }
        userImages.insert(newFile, function (err, fileObj) {
            if (err){
             // handle error
            } else {

                var currentUserId = Meteor.userId();
                var intervalHandle = Meteor.setInterval(function () {
                            console.log("Inside interval");

                            // changes here:

                            if (fileObj.hasStored("userImages")) {
                                 //checked if image was stored
                                var imagesURL = {
                                  "profile.userImg": '/cfs/files/userImages/' + fileObj._id + '/' + fileObj.name()
                                };
                                Meteor.users.update(currentUserId, {$set: imagesURL});
                                // if file has stored, stop interval
                                Meteor.clearInterval(intervalHandle);
                            }
                        }, 1000);
            }
        });
    });


}