簡體   English   中英

在哪里可以找到“流星文件”中的上載文件?

[英]Where can I get the uploaded file in Meteor Files?

我正在使用Meteor和React JS。 我還添加了流星文件。

https://github.com/VeliovGroup/Meteor-Files

通過使用此代碼,

this.Images = new FilesCollection({collectionName: 'Images'});
export default class Logo extends TrackerReact(React.Component){
    constructor(){
    ...
    Meteor.subscribe('files.images.all');
    }
uploadLogo(e){
    if (e.currentTarget.files && e.currentTarget.files[0]) {
      // We upload only one file, in case 
      // there was multiple files selected
      var file = e.currentTarget.files[0];
      if (file) {
        var uploadInstance = Images.insert({
          file: file,
          streams: 'dynamic',
          chunkSize: 'dynamic',
          transport: 'http'
        }, false);

        uploadInstance.on('start', function() {
          //template.currentUpload.set(this);
        });

        uploadInstance.on('end', function(error, fileObj) {
          if (error) {
            alert('Error during upload: ' + error.reason);
          } else {
              console.log("done");
            alert('File "' + fileObj.name + '" successfully uploaded');
          }
        });
        uploadInstance.start();
      }

    }else{
        console.log("error");
    }
}
render(){
...
<input type="file" id="fileinput" onChange={this.uploadLogo.bind(this)} />
}

我可以上傳文件,但是在目錄中看不到任何文件。 這是我的publish.js,

this.Images = new Meteor.Files({
  debug: true,
  collectionName: 'Images',
  allowClientCode: false, // Disallow remove files from Client
  onBeforeUpload: function (file) {
    // Allow upload files under 10MB, and only in png/jpg/jpeg formats
    if (file.size <= 1024*1024*10 && /png|jpg|jpeg/i.test(file.extension)) {
      return true;
    } else {
      return 'Please upload image, with size equal or less than 10MB';
    }
  }
});
Meteor.publish('files.images.all', function () {
    return Images.find().cursor;
  });

如何顯示圖像? 如何限制用戶上傳僅圖像的文件?

對我來說,他們的API文檔並不豐富。 我不明白他們在文檔中說的是什么。

默認情況下,上載的文件存儲在文件系統中。 閱讀常見問題解答:

默認情況下,文件存儲在哪里? :默認情況下,如果未將config.storagePath傳遞到Constructor中,則它等於Asset / app / uploads且相對於正在運行的腳本:

  • 在開發階段:yourDevAppDir / .meteor / local / build / programs / server

注意:應用程序重建或運行流星重置后,所有文件將被刪除。 為了在開發過程中保持存儲的持久性,請在項目文件夾之外使用絕對路徑,例如/ data目錄。

  • 在生產中:yourProdAppDir /程序/服務器

因此,您需要使用config.storagePath設置位置

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM