Git Product home page Git Product logo

skipper-gridfs's Introduction

skipper emblem - face of a ship's captain GridFS Filesystem Adapter

NPM version ย  ย  Build Status

GridFS adapter for receiving upstreams. Particularly useful for handling streaming multipart file uploads from the Skipper body parser.

Currently only supports Node 6 and up

========================================

Installation

$ npm install skipper-gridfs --save

Also make sure you have skipper installed as your body parser.

Skipper is installed by default in Sails v0.10.

========================================

Usage

req.file('avatar')
.upload({
  adapter: require('skipper-gridfs'),
  uri: 'mongodb://username:[email protected]:27017/myDatabase'
}, function whenDone(err, uploadedFiles) {
  if (err) return res.negotiate(err);
  else return res.ok({
    files: uploadedFiles,
    textParams: req.params.all()
  });
});

For more detailed usage information and a full list of available options, see the Skipper docs, especially the section on "Uploading to GridFS".

Option Type Details
uri ((string)) URI to connect to Mongo instance, e.g. mongodb://username:password@localhost:27107/databasename.
(Check mongo client URI syntax).
bucketOptions ((object)) An optional parameter that matches the GridFSBucket options (Check mongo gridfs bucket options).
mongoOptions ((object)) An optional paramter that matches the MongoClient.connect options (Check mongo client options).

========================================

Contributions

are welcomed ๐Ÿ‘Œ

See ROADMAP.md.

To run the tests:

$ URI=mongodb://username:password@localhost:27107/databasename npm test

========================================

License

MIT

skipper-gridfs's People

Contributors

dehimer avatar frostme avatar fshowalter avatar mikermcneil avatar willhuang85 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

skipper-gridfs's Issues

Exception throw when file uploaded with duplicated filename

Just wonder if it can be handled to signal the error to the upload callback instead of system quit with exception. Exception shown below when file uploaded with duplicated filename.

/node_modules/skipper-gridfs/node_modules/mongodb/lib/utils.js:98
    process.nextTick(function() { throw err; });
                                        ^
MongoError: E11000 duplicate key error index: file.fs.files.$filename_1 dup key: { : "/a.mp3" }
  at Function.MongoError.create (/node_modules/skipper-gridfs/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11)
  at toError (/node_modules/skipper-gridfs/node_modules/mongodb/lib/utils.js:114:22)
  at /node_modules/skipper-gridfs/node_modules/mongodb/lib/collection.js:972:67
  at /node_modules/skipper-gridfs/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:779:13
  at [object Object].Callbacks.emit (/node_modules/skipper-gridfs/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:95:3)
  at [object Object].messageHandler (/node_modules/skipper-gridfs/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:249:23)
  at Socket.<anonymous> (/node_modules/skipper-gridfs/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:265:22)
  at Socket.emit (events.js:107:17)
  at readableAddChunk (_stream_readable.js:163:16)
  at Socket.Readable.push (_stream_readable.js:126:10)

npm package deps are different

github and npm dependencies in package.json differ

npm:
'gridfs-stream': '~0.5.1',
mongodb: '^1.4.18'

github on master:
"gridfs-stream": "~1.1.0",
"mongodb": "~2.0",

Manteinance needed?

It looks like this module is no longer being maintained. The latest commit module was on August 2015.

Also it has some problems that could require a full rewrite or a major version bump like having a single connection for all operations and drop the use of the deprecated gridfs-stream in favor for the new GridFsBucket.

I thought that I should write my own module but maybe this will only add to confuse skipper users that now will have to choose between two modules to do the same job.

Are you interested in a maintainer with knowledge of GridFs to support this module?

adapter.rm calls cb twice when fd is not found

Hi everyone, I have encountered a small problem in your code, take a look at this excerpt from the rm function:

adapter.rm = (fd, cb) => {
    const errorHandler = (err, client) => {
        if (client) client.close();
        if (cb) cb(err);
    }

    client(options.uri, options.mongoOptions, (err, client) => {
        if (err) {
            errorHandler(err, client);
        }

        bucket(client.db(), options.bucketOptions).delete(fd, (err) => errorHandler(err, client));
        if (cb) cb();
    });
}

I need a little attention on these two lines:

bucket(client.db(), options.bucketOptions).delete(fd, (err) => errorHandler(err, client));
if (cb) cb();
  1. The second line is always executed if cb exists.
  2. The first line performs the deletion, but if no file is found with the given fd, errorHandler is called, this function in turn calls cb passing an err, if cb exists.

The problem encountered is that cb is called twice, if cb exists and no file is found with fd passed to the function, thus meeting the two rules mentioned above. So for a cb like this:

fileAdapter.rm(req.param('fd'), (err) => {
    if (err) {
        res.send(err.message);
    }
    else {
        res.send('File deleted');
    }
});

res.send is called twice, one containing the err and again without err generating the following error:

[ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

Forgiveness for English, text translated by Google Translate.

Access file metadata

adapter.read() function is used to fetch data in chunks collection that contains binary data of the stored file.

Is there any function to access file metadata in files collection? I need to fetch original filename and content-type using fd as input.

Adapter reaches connection limit and crashes process

Every method on the adapter uses

MongoClient.connect(globalOpts.uri, {native_parser:true}, function(err, db)

to get access to a db object, this opens up a new connection for every request causing a huge number of connections to be opened and not closed. The process eventually crashes. Mongo's recommended way of handling connections is to create one connection per app like so:

var MongoClient = require('mongodb').MongoClient;

MongoClient.connect("mongodb://localhost:27017/integration_test", function(err, db) {
  //adapter code here
  read:function(fd,cb){
     GridStore.exist(db, fd, globalOpts.bucket, function(err, exists) {
  }

});

I have modified the current code to work using this method, and have tested it with 100,000 requests. I can submit a pull request if you think this is a valid issue.

file download error

sailsjs v1.0.1

file download error

upload code like this

      req.file('background').upload({
        maxBytes: 10000000,
        adapter: require('skipper-gridfs'),
        uri: 'mongodb://localhost:27017/payment_db',
      }, async function (err, uploadedFiles) {
        if (err) return res.serverError(err);
        if (uploadedFiles.length === 0) {
          return res.badRequest('No file was uploaded');
        }

        const user = await User.findOne({
          email
        });

        let file = await FileManager.findOne({
          user: user.id
        });

        if (!file) {
          file = await FileManager.create({
            background: uploadedFiles[0],
            user: user.id
          }).fetch();
        } else {
          file = await FileManager.update({
            user: user.id
          },{
            background: uploadedFiles[0],
          }).fetch();
        }

        return res.ok({
          file
        });
      });

file upload it works good.

but download error.

some body help me.

dowload code like this

// https://stackoverflow.com/questions/27848934/download-image-from-skipper-gridfs-in-sails-js

module.exports.custom = {
  fileUploads: { adapter: require('skipper-gridfs'), uri: 'mongodb://localhost:27017/payment_db', },
};

FileManagerController.js
...
      let blobAdapterOpts = _.omit(sails.config.custom.fileUploads, 'adapter');
      let configuredBlobAdapter = sails.config.custom.fileUploads.adapter(blobAdapterOpts);
      let fileStream = await configuredBlobAdapter.read(file.background.fd);
      fileStream.on('error', function (err){
        return res.serverError(err);
      });
      res.contentType(file.background.type);
      return fileStream.pipe(res);
...

skipper-gridfs isn't storing chunks with node v14

After upgrade node to v14 seems right given whenDone() is triggered with NO errors and printing uploaded file callback variable values seems normal even have a file descriptor id. The problem comes when I try to download the uploaded file, it's metadata exists but file itself no, and navigator downloads an empty file of 17kb always mantaining original file name.

Problem comes since I upgraded node to v14 from v12 for an Angular 9 app compatibility(now I'm considering to dockerize to avoid this situation, but I need to fix file uploading until it). The situation is I can download with success uploaded files when node was v12, but not uploaded files with v14. When I try to get a file the error is the following:
Error: FileNotFound: file 6a5a6cda-8669-4af1-8b74-c13ecc5ed178.png was not found

I tried all skipper-gridfs versions in combination with node v14 and the same is happening.

Node version: v14.4.0

package.json have the following:

    "sails-mongo": "^1.2.0",
    "sails-mysql": "1.0.1",
    "skipper": "^0.9.0-4",
    "skipper-gridfs": "^1.0.2"

doesn't support connection URI for several hosts

mongodb://server1:27017/test.fs
works well, but
mongodb://server1:27017,server2:27017,server3:27017/test.fs
or
mongodb://server1:27017,server2:27017,server3:27017/test.fs?replicaSet=repl1
throws an exception:

App 12400 stderr: /home/sever/repos/server/node_modules/skipper-gridfs/node_modules/mongodb/lib/mongodb/mongo_client.js:409
App 12400 stderr:           throw err
App 12400 stderr:                 ^
App 12400 stderr: TypeError: Cannot read property 'collection' of null
App 12400 stderr:     at Function.GridStore.exist (/home/server/repos/server/node_modules/skipper-gridfs/node_modules/mongodb/lib/mongodb/gridfs/gridstore.js:1012:5)
App 12400 stderr:     at /home/server/repos/server/node_modules/skipper-gridfs/index.js:68:27
App 12400 stderr:     at /home/server/repos/server/node_modules/skipper-gridfs/node_modules/mongodb/lib/mongodb/mongo_client.js:406:11

The bucket definition should be not part of the URI anyway..

Upload using skipper-gridfs Express, file NOT stored in MongoDB

My angular form POST to express is
var fd = new FormData();
fd.append('avatar', file); $http.post('/upload', fd, {
transformRequest: angular.identity,
headers: {'Content-Type': 'multipart/form-data'}

Request Payload on Browser is
------WebKitFormBoundaryhfBV9Xo6gZjIcavn
Content-Disposition: form-data; name="avatar"; filename="loading.gif"
Content-Type: image/gif
------WebKitFormBoundaryhfBV9Xo6gZjIcavn--

Express Code is below
req.file('avatar')
.upload({
adapter: require('skipper-gridfs'),
uri: 'mongodb://localhost/dev.testupload'
}, function whenDone(err, uploadedFiles) {
if (err) throw err;
console.log(uploadedFiles);
res.end('Success!');});

RESULT: No errors. But file is not uploaded to Mongo. Mongo query here returns nothing - db.testupload.find({});

Appreciate your help and thanks for your contributions.

Error: FileNotFound: file [here is filename] was not found

Get error which crash my server on read operation.
It is happen when you try read file which is not exist.

Here is part of code where it is happens:

read(req, res) {
    const filename = req.params.name;

    const fileAdapter = require('skipper-gridfs')({
      uri: sails.config.gridfs.uri,
    });

    fileAdapter.read(filename, (err, file) => {
      if (err) return res.negotiate(err);
...

Error stacktrace I get in terminal:

Error: FileNotFound: file hong-kong-city.jpg was not found
    at /Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb/lib/gridfs-stream/download.js:276:17
    at result (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb/lib/utils.js:410:17)
    at session.endSession (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb/lib/utils.js:398:11)
    at ClientSession.endSession (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb-core/lib/sessions.js:134:41)
    at executeCallback (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb/lib/utils.js:395:17)
    at handleCallback (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb/lib/utils.js:128:55)
    at cursor.next (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb/lib/operations/collection_ops.js:598:5)
    at result (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb/lib/utils.js:410:17)
    at executeCallback (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb/lib/utils.js:402:9)
    at handleCallback (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb/lib/utils.js:128:55)
    at cursor._next (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb/lib/operations/cursor_ops.js:195:5)
    at handleCallback (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb-core/lib/cursor.js:204:5)
    at _setCursorNotifiedImpl (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb-core/lib/cursor.js:426:38)
    at self._endSession (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb-core/lib/cursor.js:434:46)
    at Cursor._endSession (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb-core/lib/cursor.js:195:5)
    at Cursor._endSession (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb/lib/cursor.js:231:59)
    at _setCursorNotifiedImpl (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb-core/lib/cursor.js:434:17)
    at setCursorNotified (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb-core/lib/cursor.js:426:3)
    at done (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb-core/lib/cursor.js:650:16)
    at queryCallback (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb-core/lib/cursor.js:701:18)
    at /Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb-core/lib/connection/pool.js:397:18
    at process._tickCallback (internal/process/next_tick.js:61:11)
Emitted 'error' event at:
    at __handleError (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb/lib/gridfs-stream/download.js:413:9)
    at /Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb/lib/gridfs-stream/download.js:278:14
    at result (/Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb/lib/utils.js:410:17)
    [... lines matching original stack trace ...]
    at /Users/dehimer/Projects/tempust/tempust-server/node_modules/mongodb-core/lib/connection/pool.js:397:18

Made fix in my own branch. Will share soon.

Retrieving different versions doesn't work

If you save a file multiple times with different data, then trying to retrieve anything after the first version always retrieves the first version. The problem is that the code that passes the file data on to GridStore passes the file name, not the record's ID, so it always gets the first one.

I have a simple fix in place, which I'll submit as a PR soon.

Cannot find module '../build/Release/bson'

Using the latest published version of skipper-gridfs I'm getting the following error when installing:

> bson@0.2.22 install /test/node_modules/skipper-gridfs/node_modules/bson
> (node-gyp rebuild 2> builderror.log) || (exit 0)

make: Entering directory '/test/node_modules/skipper-gridfs/node_modules/bson/build'
  CXX(target) Release/obj.target/bson/ext/bson.o
bson.target.mk:88: recipe for target 'Release/obj.target/bson/ext/bson.o' failed
make: Leaving directory '/test/node_modules/skipper-gridfs/node_modules/bson/build'

And when I lift sails, I get the following warning/error:

{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version

this has most probably something to do with the mongodb version used in the published version which is: "^1.4.18"

When I try the master branch, which has "mongodb": "~2.0", there are no installation errors anymore and sails lifts without warnings/errors.

would it be possible to publish a version with updated dependencies?

best regards

japel

URI connection returns 500 server error

I'm using sails js along with ember js, i tried to upload a file using skipper along with skipper-gridfs
the problem seems to be in the uri, i keep getting the same error 500 internal server error

i'm using kitematic docker

here is my upload method

module.exports = {
	file : function(req, res) {
		console.log(req.body);
		req.file('file').upload({
			adapter : require('skipper-gridfs'),
			uri : 'mongodb://192.168.99.100:32769/admin/upload'
		}, function (err, uploadedFiles) {
			if (err) return res.negotiate(err);
				console.log(err);
			return res.json({ message : uploadedFiles[0].fd.split('assets/')[1] })
		})
	}
};

ember uploading method

    uploadImage(file) {
      console.log(file);
      file.upload('http://localhost:1338/uploads/file').then(response => {
        console.log(response);
        this.get('model.files').pushObject({ path : response.body.message });
      })
    }

the weird thing is the error i keep getting is { err : connection to [192.168.99:27017] timed out }
this error appears like 30 seconds since the upload method run

the ip address in the error is weird somehow seems like sails js is getting the ip address from somewhere else.

i'm sorry i'm asking such a question here but i have tried to ask in stackoverflow no body responded to me yet and it's been almost 7 hours on this bug without a solution,

MongoError: Can't get executor for query { files_id: ObjectId('5863503bb05b55f81abea9b0'), n: { $gte: 0 } }

{ MongoError: Can't get executor for query { files_id: ObjectId('5863503bb05b55f81abea9b0'), n: { $gte: 0 } }
at Object.toError (e:\NodeWorkspace\Sails-Vue\node_modules\skipper-gridfs\node_modules\mongodb\lib\mongodb\utils.js:114:11)
at e:\NodeWorkspace\Sails-Vue\node_modules\skipper-gridfs\node_modules\mongodb\lib\mongodb\db.js:1196:31
at e:\NodeWorkspace\Sails-Vue\node_modules\skipper-gridfs\node_modules\mongodb\lib\mongodb\db.js:1905:9
at Server.Base._callHandler (e:\NodeWorkspace\Sails-Vue\node_modules\skipper-gridfs\node_modules\mongodb\lib\mongodb\connection\base.js:453:41)
at e:\NodeWorkspace\Sails-Vue\node_modules\skipper-gridfs\node_modules\mongodb\lib\mongodb\connection\server.js:488:18
at MongoReply.parseBody (e:\NodeWorkspace\Sails-Vue\node_modules\skipper-gridfs\node_modules\mongodb\lib\mongodb\responses\mongo_reply.js:68:5)
at . (e:\NodeWorkspace\Sails-Vue\node_modules\skipper-gridfs\node_modules\mongodb\lib\mongodb\connection\server.js:446:20)
at emitOne (events.js:96:13)
at emit (events.js:188:7)
at . (e:\NodeWorkspace\Sails-Vue\node_modules\skipper-gridfs\node_modules\mongodb\lib\mongodb\connection\connection_pool.js:207:13)
at emitTwo (events.js:106:13)
at emit (events.js:191:7)
at Socket.exports.Connection.createDataHandler (e:\NodeWorkspace\Sails-Vue\node_modules\skipper-gridfs\node_modules\mongodb\lib\mongodb\connection\connection.js:440:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:548:20)
name: 'MongoError',
ok: 0,
errmsg: 'Can't get executor for query { files_id: ObjectId('5863503bb05b55f81abea9b0'), n: { $gte: 0 } }',
code: 17241,
codeName: 'Location17241' }

saveAs?

Hi,
If I recall correctly there used to be "saveAs" option for the receiver, but cannot find it anymore...?

maxBytes support

Does skipper-grids support maxBytes option?

req.file('upfile')
  .upload({
    adapter: require('skipper-gridfs'),
    uri: uri,
    // You can apply a file upload limit (in bytes)
    maxBytes: maxBytes
  }, function (err, uploadedFiles) {

skipper-gridfs with node v18

The problem I have is that I am using nodejs v18.0.0, I have already used skipper-gridfs on other occasions and it works perfectly, the difference is that I have used node v12 or node v14 but this time this version of node is necessary, it is worth mentioning that the I create fs.files collections automatically and fs.chunks I create them manually but it only inserts them into f.chunks. I share my code:

`/**

const get_file = function(blob, fd) {
return new Promise((resolve, reject) => {
blob.read(fd, function(error , file) {
if(error) {
return reject(error);
}
return resolve(file);
});
});
}

module.exports = {
uploadFile: async(request, response)=>{
request.file('archivo').upload({
adapter: require('skipper-gridfs'),
uri: 'mongodb://127.0.0.1:27017/partidas_presupuestales'
}, function (err, filesUploaded) {
if (err) return response.serverError(err);
return response.ok();
});
},
viewdocument: async function( request, response ){
const blobAdapter = require('skipper-gridfs')({

		// uri: 'mongodb://apostillado:[email protected]:27017/apostillado'
		uri: "mongodb://127.0.0.1:27017/partidas_presupuestales"
	});

	const fd = request.param('id').split("_").join('.');

	const file = await get_file(blobAdapter, fd);

	response.contentType('application/pdf');
	return response.send(new Buffer(file));
}

};

`

I have already reviewed permissions, the connection string, I have changed the version of skipper-gridfs to a lower one, currently this is the configuration I have:

sailsjs:1.5.2
mongodb:4.2.0
skipper-gridfs: 1.0.2

Likewise, in the endpoint in postman there is POST /upload
header: Content-Type: multipart/form-data
body: form-data
key:file
value: my_file.pdf

Figure out why file is not in mongo before an LS all within the skipper adapter tests

Looking at the failing test, the file has not been written to mongo before an ls is being performed. This seems to be because the receiver__'s finish has been called before the file has been fully uploaded to mongo.

I believe the tests just don't treat the methods asynchronously. Possible should not have these tests rely on what is done in a previous test.

Cannot upload image larger than 100kb

I have been trying to upload an image around 4mb into my mongo database using skipper-gridfs however when uploading it just loads and loads then I get a CSRF Mismatch Error as I have set the CSRF to true. If I try uploading an image around 50kb it works. Is there a setting for skipper-gridfs that stops files larger than 50kb from uploading?

module.exports = {
    upload: function(req, res) {
        console.log(req.method);
        if (req.method === "GET")
            return res.json({ "status": "GET not allowed" });

        var uploadFile = req.file('uploadFile');

        uploadFile.upload({
          adapter: require('skipper-gridfs'),
          uri: 'mongodb://localhost:27017/reaam.user'

        }, function (err, filesUploaded) {

          if (err) return res.negotiate(err);

          var userId = req.session.User.id;
          var userObj = {

                profileimage: filesUploaded[0].extra.fd 
            };

            User.update(userId, userObj, function userUpdated(err){
                if(err){
                    res.json(err);
                }
            });  
          return res.redirect('/user/show/' + req.param('id'));
        }); 
    }
};

[FEATURE] uri config

Awesome to see this adapter :)

I'm mentioning your module here https://github.com/balderdashy/skipper#uploading-files-to-gridfs and as I was writing some docs, it occurred to me that it would be nice and simple to expose a uri option for configuring host/port/user/pwd/db. Would you be ok w/ something like this?

Uploading files to gridfs
$ npm install skipper-gridfs --save

skipper-gridfs is a filesystem adapter which enables Skipper to stream file uploads directly to MongoDB's GridFS.

req.file('avatar').upload({
  // ...any other options here...
  adapter: require('skipper-gridfs'),
  uri: 'mongodb://[username:password@]host1[:port1][/[database]'
}, ...);

It exposes the following adapter-specific options:

Option Type Description
uri ((string)) todo

Retrieving files

Hello! I've got a question regarding the adapter:

I'm currently using skipper-gridfs in my sails project (10.2). It's no problem to upload the files (metadata gets stored properly in files.files, and the image chunks in files.chunks). Now, I am trying to receive the images to display in my views.

Here's the problem: I don't have a clue how to do this. The adapter seems to directly write to the collections, so I cannot use sails-mongo (or waterline) to fetch the data (I suppose). Could someone provide some kind of usage example for this? Or point me to the right resources if I'm looking at this the wrong way :).

Also, on a side note, I'd like to store extra information when uploading the files (like the id of the user who's uploaded the file, the article's id etc). What's the best way to handle this?

Any help would be greatly appreciated!

no replication has been enabled, so w=2+ won't work

Hello, I'm trying to upload files to gridfs using the sample code provided, but I get this error:

no replication has been enabled, so w=2+ won't work

I don't know if I want to enable replication because my app is very small. I've looked into the code and the w is set to majority.

Aborting request

When upload is aborted I get this error:

TypeError: object is not a function
    at onwriteError (_stream_writable.js:313:5)
    at onwrite (_stream_writable.js:335:5)
    at WritableState.onwrite (_stream_writable.js:105:5)
    at Writable.<anonymous> (/app/node_modules/skipper-gridfs/index.js:227:21)
    at Writable.g (events.js:199:16)
    at Writable.emit (events.js:129:20)
    at PassThrough.<anonymous> (/app/node_modules/skipper-gridfs/index.js:246:36)
    at PassThrough.g (events.js:199:16)
    at PassThrough.emit (events.js:129:20)
    at /app/node_modules/skipper/standalone/Upstream/prototype.fatalIncomingError.js:65:17
    at Function.forEach (/app/node_modules/skipper/node_modules/lodash/dist/lodash.js:3298:15)
    at lodash.ctor.(anonymous function) [as each] (/app/node_modules/skipper/node_modules/lodash/dist/lodash.js:5925:31)
    at Upstream.fatalIncomingError (/app/node_modules/skipper/standalone/Upstream/prototype.fatalIncomingError.js:55:18)
    at /app/node_modules/skipper/lib/Parser/prototype.parseReq.js:51:10
    at Function.forEach (/app/node_modules/skipper/node_modules/lodash/dist/lodash.js:3298:15)
    at lodash.ctor.(anonymous function) [as each] (/app/node_modules/skipper/node_modules/lodash/dist/lodash.js:5925:31)
    at Form.<anonymous> (/app/node_modules/skipper/lib/Parser/prototype.parseReq.js:50:23)
    at Form.emit (events.js:129:20)
    at handleError (/app/node_modules/skipper/node_modules/multiparty/index.js:196:12)
    at IncomingMessage.onReqAborted (/app/node_modules/skipper/node_modules/multiparty/index.js:175:5)
    at IncomingMessage.emit (events.js:104:17)
    at abortIncoming (_http_server.js:279:11)
    at Socket.socketOnEnd (_http_server.js:393:7)
    at Socket.emit (events.js:129:20)
    at _stream_readable.js:908:16
    at process._tickDomainCallback (node.js:381:11) [TypeError: object is not a function]

I am running #master branch

Empty uri passed to Mongo

Hi. I'm trying to implement auto upload to gridFS and encountered a problem. Whenever uploading a file I get this error from Mongo:

Error: URL must be in the format mongodb://user:pass@host:port/dbname
    at Error (native)
    at exports.parse (/nodejs/rop-db/node_modules/skipper-gridfs/node_modules/mongodb/lib/mongodb/connection/url_parser.js:15:11)
    at Function.MongoClient.connect (/nodejs/rop-db/node_modules/skipper-gridfs/node_modules/mongodb/lib/mongodb/mongo_client.js:164:16)
    at Writable.onFile (/nodejs/rop-db/node_modules/skipper-gridfs/index.js:205:29)

My code looks like this:

req.file('user-avatar').upload({
            adapter: require('skipper-gridfs'),
            uri: sails.config.connections.mongo.url
        }, function (err, filesUploaded) {
            ...
        });

So I digged deeper and so the following:
In skipper-gridfs/index.js:205
screen shot 2015-07-23 at 10 41 46 am
So the globalOpts.uri is empty.
But a few lines up where options = _.defaults(options, globalOpts); I see
screen shot 2015-07-23 at 10 43 55 am
Where the uri is correct.

Don't know what happens before this code but it seems MongoClient.connect should receive options.uri instead?

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.