Giter Club home page Giter Club logo

meteor-jalik-ufs-gridfs's Introduction

UploadFS GridFS Store

A Mongo GridFS store for UploadFS.

Installation

To install the package, execute this command in the root of your project :

meteor add jalik:ufs-gridfs

If later you want to remove the package :

meteor remove jalik:ufs-gridfs

Creating a Store

The code below is available on the client and the server.

GridFS store files in a Mongo database by cutting them in chunks.

import {Mongo} from 'meteor/mongo';
import {UploadFS} from 'meteor/jalik:ufs';
import {GridFSStore} from 'meteor/jalik:ufs-gridfs';

// Declare store collection
const Photos = new Mongo.Collection('photos');

// Declare store
const PhotoStore = new GridFSStore({
    collection: Photos,
    name: 'photos',
    chunkSize: 1024 * 255
});

License

This package is released under the MIT License.

meteor-jalik-ufs-gridfs's People

Contributors

engelgabriel avatar gmsecrieru avatar jalik avatar rodrigok avatar snowwolfjay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

meteor-jalik-ufs-gridfs's Issues

copyTo "File does not exist"

Does gridFS not support the copyTo option? I always get

(STDERR) ufs: cannot copy file "4Ra9AM3fkaCCWAgzj" (File does not exist)

The id does exist in collection uploadfs.files

_id :   4Ra9AM3fkaCCWAgzj
filename    :   4Ra9AM3fkaCCWAgzj
contentType :   image/png
length  :   32358
chunkSize   :   261120
uploadDate  :   2016-08-10 12:12:56
aliases :   null
metadata    :   null
md5 :   1592f38d5e1f8da15783b899d6c72305

And delivers the wanted file.
https://github.com/jalik/jalik-ufs/blob/master/ufs-store.js#L147

But catches the error when store.write is executed.
https://github.com/jalik/jalik-ufs/blob/master/ufs-store.js#L174

It works when using the local addon. What do I miss?

Meteor.photos = new Mongo.Collection('photos')
Meteor.thumbnails128 = new Mongo.Collection('thumbnails-128')
Meteor.thumbnails64 = new Mongo.Collection('thumbnails-64')

Meteor.thumbnail128Store = new UploadFS.store.GridFS({
  collection: Meteor.thumbnails128,
  name: 'thumbnails-128',
  chunkSize: 1024 * 255,
  transformWrite: function(readStream, writeStream, fileId, file) {
    let gm = Npm.require('gm')
    if (gm) {
      gm(readStream)
        .resize(128, 128)
        .gravity('Center')
        .extent(128, 128)
        .quality(75)
        .stream().pipe(writeStream)
    } else {
      console.error("gm is not available", file)
    }
  }
})

Meteor.thumbnail64Store = new UploadFS.store.GridFS({
  collection: Meteor.thumbnails64,
  name: 'thumbnails-64',
  chunkSize: 1024 * 255,
  transformWrite: function(readStream, writeStream, fileId, file) {
    let gm = Npm.require('gm')
    if (gm) {
      gm(readStream)
        .resize(64, 64)
        .gravity('Center')
        .extent(64, 64)
        .quality(75)
        .stream().pipe(writeStream)
    } else {
      console.error("gm is not available", file)
    }
  }
})

Meteor.photosStore = new UploadFS.store.GridFS({
  collection: Meteor.photos,
  name: 'photos',
  chunkSize: 1024 * 255,
  filter: new UploadFS.Filter({
    minSize: 1,
    maxSize: 1024 * 1000, // 1MB,
    contentTypes: ['image/*']
  }),
  copyTo: [
    Meteor.thumbnail128Store,
    Meteor.thumbnail64Store
  ]
})

Version 0.2.1: Cannot correctly read small audio files (< 256 kB)

Hi @jalik,

Please help me with this issue:

When I use the version 0.2.1 of the jalik:ufs-gridfs package my app cannot correctly read audio files that are less then 256 kB. Files with sizes that are larger than 256 kB are loaded and played fast and correctly. If I use the version 0.1.4, everything is OK for files of any size.

The behavior of the app is a little different in FireFox and Chrome (I'm using the latest versions of both ).

FF: when starting loading an audio file of, for example, 37 kB in size, the browser waits for exactly 120 seconds and then loads the file correctly (all 37 kB) with the status 206, and the app plays it.

Chrome: for the same file that is mentioned above the browser loads first 22 kB with the status 206 and the app plays them. But after about 2 minutes the browser indicates the error net::ERR_CONTENT_LENGTH_MISMATCH, then 6 times net::ERR_EMPTY_RESPONSE, -- and the status is changed from 206 to (failed). At the end the error 503 (Service Unavailable) is shown for the file under consideration and it can't be played.

Meteor's version: Now I use 1.5.1 version but that issue is seen for other versions too, e.g., for 1.4.3.2.
Code for the store is standard:

AudiosStore = new UploadFS.store.GridFS({ // or AudiosStore = new GridFSStore({... - no difference
  collection: Audios,
  name: 'audios',
  chunkSize: 1024 * 255,
  ...

Thanks in advance!

Delete file logs error if several stores share a single collection

Hi,

I use multiple stores to check the file extensions, but all stores share a single collection. When deleting a file by calling Files.remove(fileId); an error is logged in the delete method because the file is not found in each store:

 this.delete = function (fileId, callback) {
    if (typeof callback !== 'function') {
        callback = function (err) {
            if (err) {
                console.error(err);
            }
        }
    }
    // TODO check if fileId really exists in this mongostore before calling delete
    return mongoStore.delete(fileId, callback);
};

...

export const Files = new Mongo.Collection('uploads');

export const PdfStore = new MultiGridFSStore({
    collection: Files,
    collectionName: 'pdf_store',
    name: 'pdf',
    filter: new UploadFS.Filter({onCheck: file => checkUploadFile(file, ['pdf'])})
});

export const PresentationStore = new MultiGridFSStore({
    collection: Files,
    collectionName: 'presentation_store',
    name: 'presentation',
    filter: new UploadFS.Filter({onCheck: file => checkUploadFile(file, ['ppt', 'pptx'])})
});

I've inserted a TODO, but I am not sure if this is possible. Currently I modified the implementation and removed the console logging.

Thanks
Oliver

`Finish` event emits twice

Hello!

Since v3.6.6 of npm mongodb library gridfs-stream emits close event along with finish event. The behaviour is changed by this commit. But in your jalik:ufs-gridfs library finish event emitting manually after close here, as a result we have finish event emitted 2 times.

So at this moment to work properly npm-mongo package of meteor should be at version v3.8.1 or less, since it depends on older version of mongodb.

Facilitate conversion from CollectionFS

jalik/meteor-jalik-ufs#14

Making the gridfs collections compatible with the structure used by CFS would be great... At least the capability to store user fields (as in metadata) and using same format for _id (obj instead of meteor string) would make it possible to point at the same gridfs collection from this package and from CFS...

Many thanks for considering.

File reading issue

Hi , I am getting issue during the view file. Files are successfully uploaded but getting error during the read file. When open file on Browser using "url" fields

Error: `value` required in setHeader("Content-Type", value).
  at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:342:11)
  at ServerResponse.res.setHeader 

   at packages/jalik:ufs/ufs-server.js:340:37
   at Domain.<anonymous> (packages/jalik:ufs/ufs-server.js:236:81)
   at Domain.run (domain.js:228:14)
   at packages/jalik:ufs/ufs-server.js:234:15
   at Object.handle (packages/jalik:ufs/ufs-server.js:188:39)
   at next
export const FilesStore = new UploadFS.store.GridFS({
--
  | collection: Files,
  | name: 'files',
  | chunkSize: 1024 * 255,
  | filter: new UploadFS.Filter({
  | contentTypes: ['application/pdf']
  | })

/* To upload file */
const upload = new UploadFS.Uploader({
--
  | data,
  | file,
  | store: FilesStore,
  | onError: reject,
  | onComplete: resolve
  | });
  | upload.start();
  |  
  | });

function uploadGridFS(uploadedFile) {
--
  | return new Promise((resolve, reject) => {
  | // pick from an object only: name, type and size
  |  
  | const file = {
  | name:uploadedFile.name,
  | type:uploadedFile.type,
  | size: uploadedFile.size   };
  | var data=uploadedFile;
  | const upload = new UploadFS.Uploader({
  | data,
  | file,
  | store: FilesStore,
  | onError: reject,
  | onComplete: resolve
  | });
  | upload.start();
  |  
  | });
  | }

File name is being set to _id

When uploading a file, the file name in the mongodb collection.files is being set to _id instead of the file name uploaded. This causes the url to be based on _id.extension instead of filename. for images to be displayed in the app, not a big deal, but when downloading the file, it does matter.

different database for gridfs

I want to save images to different database instead of default one.

I have changed the collection driver and now images collection is being created on different database but not others collections that hold files.

check my code:

if(Meteor.isServer){
    var d = new MongoInternals.RemoteCollectionDriver('mongodb://test123:[email protected]:29725/test');
    Images = new Mongo.Collection('images', { _driver: d });
}else{
    Images = new Mongo.Collection('images');
}

function loggedIn(userId) {
    return !!userId;
}

Images.allow({
    insert: loggedIn,
    update: loggedIn,
    remove: loggedIn
});


ImagesStore = new UploadFS.store.GridFS({
    collection: Images,
    name: 'images',
    filter: new UploadFS.Filter({
        contentTypes: ['image/*']
    })
});

any suggestion or help ? how can i achive it ?

GridFSStore is not a function

I have to use new UploadFS.store.GridFS({ })

If I use new GridFSStore({ }) (like shown in this readme) I get the error TypeError: GridFSStore is not a function

v. 0.2.1 breaks the transformWrite() method work

Hi,

I've just updated the package to the version 0.2.1 in my app and found that the app cannot transfer data after transformWrite() method execution any more.

When I save a file that should be transformed I get a message from transformWrite() that transformation is ended successfully but it looks like that corresponding pipe(to) operation is not performed: no message from the onFinishUpload method is sent, the file property uploading is always true and doesn't change to false.

If I go back to the version 0.1.4, everything works normally. Also, if there is no transformation (i.e. the single operation from.pipe(to); is perform in the transformWrite() method) it works OK too.

Meteor: 1.4.3.2
UFS: 0.7.4_1

Looking forward for your answer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.