0

我对编程很陌生。我正在学习如何将 CollectionFS 与 Angular 一起使用,但无法从数据库中取回文件。这是我的代码:

html:

 <body>
  <div class="container" ng-app="upload">
    <div ng-controller="uploadCtrl">
      <form id="uploadForm" >
        <input type="file" id="file">
        <button ng-click="uploadPhoto()">Pobierz</button>
      </form>
      <ul>
        <li  ng-repeat="zdjecie in zdjecia">
            <img ng-src="{{ zdjecie.url }}" />
        </li>
      </ul>
    </div>
  </div>
</body>

角度:

angular.module('upload', ['angular-meteor']);

angular.module('upload').controller('uploadCtrl', ['$scope', '$meteor',
  function ($scope, $meteor) {

    $scope.zdjecia = $meteor.collectionFS(Zdjecia, false, Zdjecia);
    var fileInput = document.getElementById('file');

    $scope.uploadPhoto = function () {
    var file = fileInput.files[0];
    $scope.zdjecia.save(file);
  };
}]);

后端:

Zdjecia = new FS.Collection("zdjecia", {
  stores: [
    new FS.Store.FileSystem("zdjecia"), { path : '~/zdjecia'}
  ]
});

if (Meteor.isServer) {
  Zdjecia.allow({
    insert: function () {
      return true;
    }
  });
}

我真的不明白,如何从数据库中获取文件,它们也没有出现在路径文件夹中。

4

0 回答 0