CollectionFS / Meteor-CollectionFS上传0字节的文件

时间:2015-08-01 10:24:51

标签: file-upload meteor dropbox-api collectionfs

我正在尝试将文件上传到Dropbox应用。使用包CollectionFS/Meteor-CollectionFScfs:dropbox适配器,我的问题是上传的文件是0字节。我不确定我在这里遗失或做错了什么。

在服务器上:

var registrationImageStorage = new FS.Store.Dropbox("registrationStorage", {
  key: "****",
  secret: "****",
  token: "****",
  transformWrite: function (fileObj, readStream, writeStream) {
    gm(readStream, fileObj.name()).stream().pipe(writeStream);
  }
});

RegistrationImages = new FS.Collection("registrations", {
  stores: [registrationImageStorage],
  filter: {
    allow: {
      contentTypes: ['image/*']
    }
  }
});

RegistrationImages.allow({
  insert: function () {
    return true;
  },
  update: function () {
    return true;
  }
});

在客户端:

var registrationImageStorage = new FS.Store.Dropbox("registrationStorage");

RegistrationImages = new FS.Collection("registrations", {
  stores: [registrationImageStorage],
  filter: {
    allow: {
      contentTypes: ['image/*']
    }
  }
});

在客户端上开始上传:

var file = new FS.File($('#badgeImage').get(0).files[0]);

    RegistrationImages.insert(file, function (err, fileObj) {
      if (err) {
        console.log(err);
      } else {
        console.log(fileObj);
    });

1 个答案:

答案 0 :(得分:1)

好的,我不需要这部分代码,删除后,它可以工作:

transformWrite: function (fileObj, readStream, writeStream) {
    gm(readStream, fileObj.name()).stream().pipe(writeStream);
  }