我正在尝试使用 Dropbox 进行上传,但出了点问题,我不知道它是什么。我在互联网上进行了一些搜索,但找不到任何东西。
这是我的代码:
if (Meteor.isClient) {
Template.hello.helpers({
uploads:function(){
return Avatars.find();
},
images:function(){
return Images.find();
}
});
var avatarStoreLarge = new FS.Store.Dropbox("avatarsLarge");
var avatarStoreSmall = new FS.Store.Dropbox("avatarsSmall");
Avatars = new FS.Collection("avatars", {
stores: [avatarStoreSmall, avatarStoreLarge],
filter: {
allow: {
contentTypes: ['image/*']
}
}
});
Template.hello.events({
'change .fileInput':function(event,template){
FS.Utility.eachFile(event,function(file){
var fileObj = new FS.File(file);
Avatars.insert(fileObj,function(err){
console.log(err);
})
})
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
var avatarStoreLarge = new FS.Store.Dropbox("avatarsLarge", {
key: "xxxxxxxxxxxxxxx",
secret: "xxxxxxxxxxxxxxx",
token: "xxxxxxxxxxxxxxx",
transformWrite: function(fileObj, readStream, writeStream) {
gm(readStream, fileObj.name()).resize('250', '250').stream().pipe(writeStream)
}
})
var avatarStoreSmall = new FS.Store.Dropbox("avatarsSmall", {
key: "xxxxxxxxxxxxxxx",
secret: "xxxxxxxxxxxxxxx",
token: "xxxxxxxxxxxxxxx",
beforeWrite: function(fileObj) {
fileObj.size(20, {store: "avatarStoreSmall", save: false});
},
transformWrite: function(fileObj, readStream, writeStream) {
gm(readStream, fileObj.name()).resize('20', '20').stream().pipe(writeStream)
}
})
Avatars = new FS.Collection("avatars", {
stores: [avatarStoreSmall, avatarStoreLarge],
filter: {
allow: {
contentTypes: ['image/*']
}
}
})
});
}
我按照这个文档做了这个例子。