文件上传不适用于meteor JS

时间:2016-04-26 12:18:22

标签: meteor

 Meteor.startup(function(){
   console.log(process.env.PWD);
   UploadServer.init({
      tmpDir: process.env.PWD + '/.uploads/tmp',
      uploadDir: process.env.PWD + '/.uploads/',
      getDirectory: function(file, formData) {
        return formData.contentType;
      },
        finished: function(file, folder, formFields){
          console.log(file.name); // ServerSession.set('image_name', file.name);
        }
    })
  });

这是我的代码没有任何帮助吗?

由于

1 个答案:

答案 0 :(得分:0)

你忘了checkCreateDirectories设置为true。如果您没有将此设置为真,那么您必须直接手动创建这里的例子,你怎么能这样做

Meteor.startup(function () {
  UploadServer.init({
    tmpDir: process.env.PWD + '/.uploads/tmp',
    uploadDir: process.env.PWD + '/.uploads/',
    checkCreateDirectories: true,
    getDirectory: function(fileInfo, formData) {
      // create a sub-directory in the uploadDir based on the content type (e.g. 'images')
      return formData.contentType;
    },
    finished: function(fileInfo, formFields) {
      // perform a disk operation
    },
    cacheTime: 100,
    mimeTypes: {
        "xml": "application/xml",
        "vcf": "text/x-vcard"
    }
  });
});

另外请使用collection-FS查看文件上传,它提供了很多好东西。请检查我的github演示https://github.com/PankajJatav/meteor-image-upload-demo