标签: collectionfs

如何在插入时引用另一个集合?

我正在尝试如何获取Image(使用CollectionFS的文件)并将Image的Id插入到我的Items imageId字段中:

LIB /收藏/ items.js

Items = new Mongo.Collection("items");
Items.attachSchema(new SimpleSchema({
  name: {
    type: String,
    label: "Name",
  },
  userId: {
    type: String,
    regEx: SimpleSchema.RegEx.Id,
    autoform: {
      type: "hidden",
      label: false
    },
    autoValue: function () { return Meteor.userId() },
  },
  image: {
    type: String,
    optional: true,
    autoform: {
      label: false,
      afFieldInput: {
        type: "fileUpload",
        collection: "Images",
        label: 'Select Photo',
      }
    }
  },
  imageId: {
   type: String
  }
}));
Run Code Online (Sandbox Code Playgroud)

LIB /收藏/ images.js

if (Meteor.isServer) {
  var imageStore = new …
Run Code Online (Sandbox Code Playgroud)

javascript meteor meteor-helper collectionfs

13
推荐指数
1
解决办法
626
查看次数

如何从CollectionFS获取文件(图像)的缓冲区

我正在尝试将图像插入到pdf中,我正在使用PDFkit创建服务器端.我正在使用cfs:dropbox来存储我的文件.在我使用cvs:filesystem之前,很容易将图像添加到我的pdf中,因为它们就在那里.现在它们被远程存储,我不知道如何添加它们,因为PDFkit不支持仅使用url添加图像.但是,它会接受一个缓冲区.如何从我的CollectionFS文件中获取缓冲区?

到目前为止,我有这样的事情:

var portrait = Portraits.findOne('vS2yFy4gxXdjTtz5d');
readStream = portrait.createReadStream('portraits');
Run Code Online (Sandbox Code Playgroud)

到目前为止,我试过两种方式获取缓冲区:

首先使用dataMan,但最后一个命令永远不会回来:

var dataMan = new DataMan.ReadStream(readStream, portrait.type());
var buffer = Meteor.wrapAsync(Function.prototype.bind(dataMan.getBuffer, dataMan))();
Run Code Online (Sandbox Code Playgroud)

第二次手动缓冲流:

var buffer = new Buffer(0);
readStream.on('readable', function() {
    buffer = Buffer.concat([buffer, readStream.read()]);
});
readStream.on('end', function() {
    console.log(buffer.toString('base64'));
});
Run Code Online (Sandbox Code Playgroud)

这似乎永远不会回来.我仔细检查了我的文档以确保它在那里并且它有一个有效的URL并且当我将URL放入浏览器时图像出现.我错过了什么吗?

javascript node.js meteor node-pdfkit collectionfs

12
推荐指数
1
解决办法
1358
查看次数

Meteor.JS CollectionFS视频到图像缩略图(图形Magick)

我正在使用一个Meteor应用程序,我正在使用CollectionFS上传文件.

我可以上传和生成图像的缩略图.

但我的问题是:我应该如何为视频创建缩略图?

我可以看到它可以通过命令行:https://superuser.com/questions/599348/can-imagemagick-make-thumbnails-from-video

但是我如何将其应用于我的Meteor代码.

这是我在做的事情:

VideoFileCollection = new FS.Collection("VideoFileCollection", {
stores: [
  new FS.Store.FileSystem("videos", {path: "/uploads/videos"}),
  new FS.Store.FileSystem("videosthumbs", {path: "/uploads/videosthumbs",
    beforeWrite: function(fileObj) {
      // We return an object, which will change the
      // filename extension and type for this store only.
      return {
        extension: 'png',
        type: 'image/png'
      };
    },
    transformWrite: function(fileObj, readStream, writeStream) {
      gm(readStream, fileObj.name()).stream('PNG').pipe(writeStream);

    }
  })
]
});
Run Code Online (Sandbox Code Playgroud)

这里发生了什么,视频上传到"视频"文件夹,一个PNG在"videosthumbs"下创建,0字节,缩略图没有生成.

我也读过:https://github.com/aheckmann/gm#custom-arguments

我们可以使用:gm().command() - 自定义命令,如识别或转换

任何人都可以告诉我如何处理这种情况?

感谢致敬

node.js graphicsmagick meteor node-gm collectionfs

7
推荐指数
1
解决办法
580
查看次数

Meteor CollectionFS:S3 GraphicsMagick不会调整图像大小

我正在使用Meteor-CollectionFS和GraphicsMagick 1.3.22调整上传到Amazon S3的图像的大小.图像不会调整大小,它只显示在S3全尺寸中.我还尝试将调整大小的图像放在一个单独的商店中,但图像在新商店中仍然显示为全尺寸.

这是我的server/collections.js

FS.debug = true;

var imageStore = new FS.Store.S3("images", {
    bucket: "meteor-s3-test-data",
    accessKeyId: "XXX",
    folder: "images",
    secretAccessKey: "XXX",
    transformWrite: createThumb
});

var createThumb = function(fileObj, readStream, writeStream) {
    gm(readStream, fileObj.name()).resize('100', '100').stream().pipe(writeStream);
};

ProfileCollection = new Mongo.Collection('ProfileCollection');

PhotoCollection = new FS.Collection("PhotoCollection",
{
    stores: [
        imageStore,
    ],
    filter: {
      maxSize: 3145728,
      allow: {
        contentTypes: ['image/*'],
        extensions: ['png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG']
      }
    }
});
Run Code Online (Sandbox Code Playgroud)

和我的客户/ collections.js

var imageStore = new FS.Store.S3("images");

ProfileCollection = new Mongo.Collection('ProfileCollection');

PhotoCollection = new …
Run Code Online (Sandbox Code Playgroud)

image-processing amazon-s3 graphicsmagick meteor collectionfs

7
推荐指数
1
解决办法
239
查看次数

gm:如果图像大于1000px,则调整图像大小

我试图通过gmin 进行一些图像处理collectionFS,因为我需要读取一个流并将其写回同一个文件,我必须使用一个临时文件 - 如下所示.

我想检查图像是否宽于1000px.在这种情况下,它应该重新调整为1000px.

不幸的是,这不起作用,因为我得到了错误TypeError: Object [object Object] has no method 'pipe'和Error: gm().stream() or gm().write() with a non-readable stream.

var fs       = Npm.require('fs'),
    file     = Images.findOne({ _id: fileId }),
    read     = file.createReadStream('public'),
    filename = '/tmp/gm_' + Date.now(),
    temp     = fs.createWriteStream(filename);

if (method == 'resize') {
    // resize to 1000px, if image is bigger
    gmread = gm(read);
    gmread.size(function(err, size){
        if(size.width > 1000) {
            gmread.resize('1000').stream();
        }
    });
}

gmread.on('end', Meteor.bindEnvironment(function (error, result) {
    if …
Run Code Online (Sandbox Code Playgroud)

javascript graphicsmagick meteor collectionfs

6
推荐指数
1
解决办法
333
查看次数

使用graphicsmagick在collectionFS中出现意外的空写入流

我正在使用CollectionFS来管理图像.此外,我正在使用graphicsmagick gm()来处理图像.

现在我想要裁剪已保存的图像.因此,在单击事件上调用服务器方法,该方法执行crop().但是在这样做之后,我在集合中找到了一个size=0在正确日期更新的空图像.

我没有看到,我做错了什么.

shared.js

Images = new FS.Collection("images", {
    stores: [
        new FS.Store.FileSystem("thumbnail", { 
            transformWrite: function(fileObj, readStream, writeStream) {
                gm(readStream, fileObj.name()).autoOrient().resize('96', '96' + '^').gravity('Center').extent('96', '96').stream().pipe(writeStream);
            } 
        }),
        new FS.Store.FileSystem("public"),
    ]
});
Run Code Online (Sandbox Code Playgroud)

server.js

Meteor.methods({
    'crop': function (fileId, selection) {
        var file = Images.findOne({ _id: fileId }),
            read = file.createReadStream('public'),
            write = file.createWriteStream('public');

        gm(read)
            .crop(selection.width, selection.height, selection.left, selection.top)
        .stream()
        .pipe(write);
    }
});
Run Code Online (Sandbox Code Playgroud)

client.js

Template.editor.events({
    'click #crop': function () { 
        var fileId      = '123456789',
            selection   = { height: 100, …
Run Code Online (Sandbox Code Playgroud)

javascript graphicsmagick meteor collectionfs

5
推荐指数
1
解决办法
177
查看次数

Meteor CollectionFS - 在服务器上上传图像

我正在使用Meteor CollectionFS.目前我的文件上传是在客户端上执行的.我想在服务器上执行文件上传,以便其他平台如andriod或ios可以使用我的文件上传服务.

目前这是我的代码:

client.html

<input type="file" custom-on-change="uploadFile">
Run Code Online (Sandbox Code Playgroud)

clientController.js

app.controller('clientController', function ($scope, $meteor, $filter) {

    $scope.uploadFile = function(event){

        var files = event.target.files;

        for (var i = 0, ln = files.length; i < ln; i++) {

            files[i].userId = Meteor.userId();

            Images.insert(files[i], function (err, fileObj) {

            });
        }
    };
});
app.directive('customOnChange', function() {
  return {
    restrict: 'A',
    link: function (scope, element, attrs) {
      var onChangeHandler = scope.$eval(attrs.customOnChange);
      element.bind('change', onChangeHandler);
    }
  };
});
Run Code Online (Sandbox Code Playgroud)

Schema.js

Images = new FS.Collection("images", {
    stores: [
      new FS.Store.FileSystem("images", {path: '~/uploads'}) …
Run Code Online (Sandbox Code Playgroud)

image-resizing graphicsmagick angularjs meteor collectionfs

5
推荐指数
1
解决办法
718
查看次数

如果在角度meteor和集合f中上传faild,如何取消文件上传并自动删除记录?

HTML:

<div
  ngf-select
  ngf-keep="true"
  ng-model="vm.photos"
  ngf-accept="'image/*'"
  ngf-pattern="'image/*'"
  ngf-multiple="true">
  Select
</div>
<button ng-click="vm.uploadPhotos()">Upload</button>
Run Code Online (Sandbox Code Playgroud)

客户端JS:

vm.uploadPhotos = function() {
  _.forEach(vm.photos, function(photo) {
      PhotoCol.insert(photo);
  });
};
Run Code Online (Sandbox Code Playgroud)

服务器JS:

PhotoCol = new FS.Collection('propertyPhoto', {
  stores: [
    new FS.Store.FileSystem('original')
  ],
  filter: {
    allow: {
      contentTypes: ['image/*']
    }
  }
});

PhotoCol.allow({
  insert: function() {
    return true;
  },
  update: function() {
    return true;
  },
  remove: function() {
    return true;
  },
  download: function() {
    return true;
  }
});
Run Code Online (Sandbox Code Playgroud)

上传开始时,我需要一种方法来取消一个或所有上传过程.并且CollectionFS在上传完成之前在数据库中创建记录,因此如果由于某种原因用户在完成上传过程之前终止了浏览器,那么我将有一个没有上传文件的照片条目.在这里,我需要捕获该错误以从DB中删除条目.有任何想法吗?

angularjs meteor collectionfs ng-file-upload angular-meteor

5
推荐指数
0
解决办法
494
查看次数

如何从命令行查询Meteor中的FS集合?

从命令行运行meteor mongo和查询集合非常有用,用于调试目的等.

最近,我添加了collectionFS包以在数据库中启用图像存储.但是,我无法从命令行查询数据库.

db.fs.collection_name.find() 没有做的伎俩,我似乎无法在任何地方找到正确的命令.

database image mongodb meteor collectionfs

3
推荐指数
1
解决办法
760
查看次数

使用Meteor-CollectionFS上传Meteor文件,找不到错误方法

我正在使用以下meteor包上传图像

https://github.com/CollectionFS/Meteor-CollectionFS

我正在使用的代码

Uploads =new FS.Collection('uploads',{
  stores: [new FS.Store.FileSystem('uploads',{path:'~/projectUploads'})]
});

if (Meteor.isClient) {

  Template.makedobox3.events({

       'change .fileinput':function(event,template){
        FS.Utility.eachFile(event,function(file){
        var fileObj=new FS.File(file);
        Uploads.insert(fileObj,function(err){
            console.log(err);
        });


      })
   }
  });  
}
Run Code Online (Sandbox Code Playgroud)

我尝试在控制台中上传文件时收到错误

M ... rm ... e.errorClass {错误:404,原因:"未找到方法",详情:未定义,消息:"找不到方法[404]"

我在窗口环境中.安装了自动发布和不安全的软件包.我不确定我错过了什么?

meteor collectionfs

3
推荐指数
1
解决办法
849
查看次数

如何使用cfs:filesystem和collectionfs保存到Meteor中的/ public?

/lib/collections/images.js

var imageStore = new FS.Store.FileSystem("images", {
  // what should the path be if I want to save to /public/assets?
  // this does not work
  path: "/assets/images/", 
  maxTries: 1
});

Images = new FS.Collection("images", {
  stores: [imageStore]
});

Images.deny({
  insert: function() {
    return false;
  },
  update: function() {
    return false;
  },
  remove: function() {
    return false;
  },
  download: function() {
    return false;
  }
});

Images.allow({
  insert: function() {
    return true;
  },
  update: function() {
    return true;
  },
  remove: function() { …
Run Code Online (Sandbox Code Playgroud)

meteor collectionfs

2
推荐指数
2
解决办法
2101
查看次数