meteor :将文件上传到文件夹

标签 meteor

我是 Meteor 的新手。我试图找到一种上传文件的方法 我逐步使用 fs 集合遵循了这个教程:http://meteortuts.com/category/addanuploader 但是,它不起作用。什么都没发生!有什么东西不见了吗? 我在本地尝试过并在 apps.meteor.com 上部署它。 在“ uploadexample.meteor.com ”上,出现错误,因为该站点无法识别“~”字符。在本地,显示页面但未上传任何内容。任何的想法? 感谢您的回复,

米歇尔克 这是我的代码:

HTML:

    <head>
  <title>uploadexample</title>
</head>

<body>
  <h1>Welcome to Meteor!</h1>
  <div class="container">
    {{> hello}}
  </div>

</body>

<template name="hello">
  <div class="panel panel-default push-down">
    <div class="panel-heading">
      <h3 class="panel-title">Uploads Section</h3>
    </div>
    <div class="panel-body">
      <p>
        Add Files
        <span class="btn btn-default btn-file">
          <input multiple type="file" name="file" class="file fileInput"/>
        </span>
      </p>
    </div>
    <div class="panel-footer">
        <div class="col-md-9">
          <table class="table table-hover table-striped table-bordered">
            <thead>
            <th>Name</th>
            <th>Download</th>
            </thead>
            <tbody>
              {{#each uploads}}
              <tr>
                <td>{{name}}</td>
                <td><a href="{{url download=true}}" type="button" class="btn btn-default">
                  Download
                </a></td>
              </tr>
              {{/each}}
            </tbody>
          </table>
        </div>
    </div>
  </div>
</template>

js文件:

    Uploads = new FS.Collection('uploads',{
  stores:[new FS.Store.FileSystem('uploads',{path:'~/projectUploads'})]
});
if (Meteor.isClient) {
  // counter starts at 0
  Session.setDefault("counter", 0);

  Template.hello.helpers({
    counter: function () {
      return Session.get("counter");
    },
    uploads:function(){
      return Uploads.find();
    }
  });

  Template.hello.events({
    'change .fileInput':function(event,tmpl){
      FS.Utility.eachFile(event,function(file){
        var fileObj = new FS.File(file);
        Uploads.insert(fileObj),function(err){
          console.log(err);
        }
      })
    }
  });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
  });
}

meteor 列表包:

...tuto meteor/upload fs/uploadexample$ meteor list
bootstrap              1.0.1  Front-end framework from Twitter
cfs:filesystem         0.1.1  Filesystem storage adapter for CollectionFS
cfs:standard-packages  0.5.3  Filesystem for Meteor, collectionFS
meteor-platform        1.2.1  Include a standard set of Meteor packages in your app
twbs:bootstrap         3.3.2  Bootstrap (official): the most popular HTML/CSS/JS framework for responsive, mobile first projects

最佳答案

我一直在搜索与您的类似的东西。当您的应用程序使用 meteor 在本地运行时,它确实会使 ~/projectUploads 显然进入您的本地主文件夹。但是,当您希望您的应用程序在 meteor 托管 meteor deploy example.meteor.com 上运行时,您应该将路径编辑为 ./projectUploads。一切都应该工作正常。 双手合十

关于 meteor :将文件上传到文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28174389/

相关文章:

javascript - 计算文档中数组中的元素数量

javascript - Meteor 渲染回调和应用 jQuery 插件

javascript - 使用 Meteor session 切换模板

facebook - Meteor Facebook 登录 (Meteor.loginWithFacebook) 提取公共(public)个人资料、电子邮件和 user_friends 时出现问题

javascript - 尝试在单击单独的按钮 Bootstrap 时更改模式中的导航选项卡事件类

javascript - 需要更改 JS 事件格式以适应 Jquery 和 Meteor (Template.mysite.events) 格式

mongodb - 在新的 Meteor 应用程序开发中使用本地 MongoDB 而不是 minimongo

javascript - meteor 列表项目数量

node.js - Meteor 多标签共享状态

javascript - 从哪里获得事件类型列表?