mohsinali1317
mohsinali1317

Reputation: 4425

Uploading and showing images in Meteor

I am new to meteor, what I am trying to do is upload an image store it in the file system and then simply display the images I have loaded.

I am also creating a thumbnail of the images I am uploading like this

var createThumb = function(fileObj, readStream, writeStream) {
// Transform the image into a 10x10px thumbnail
gm(readStream, fileObj.name()).resize('10', '10').stream().pipe(writeStream);
};

Images = new FS.Collection("images", {
stores: [
    new FS.Store.FileSystem("thumbs", { transformWrite: createThumb }),
    new FS.Store.FileSystem("images", {path: "~/uploads"})
],
filter: {
    allow: {
        contentTypes: ['image/*'] //allow only images in this FS.Collection
    }
}
});

I have couple of issues, first of all I want to specify a path on the computer where I can store the image. I am not sure how I do that. I have created a public folder in the project and would like to store the images there.

When I start doing the thumbnail thing it is not working at all. I am not sure if the images (both original and the thumbnail) are even uploaded.

Can anyone explain or point towards me a good tutorial?

Upvotes: 0

Views: 71

Answers (1)

Lucas Blancas
Lucas Blancas

Reputation: 561

Here are some tutorials

I haven't used Collection FS in a few months, but this code below should work.

Images = new FS.Collection("images", {
    stores: [
        new FS.Store.FileSystem("thumbs", { path: "~/public/thumbs", transformWrite: createThumb }),
        new FS.Store.FileSystem("images", { path: "~/public/images" })
    ],
    filter: {
        allow: {
            contentTypes: ['image/*'] //allow only images in this FS.Collection
        }
    }
});

Upvotes: 1

Related Questions