multer-gridfs-storage
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -0,1 +1,12 @@ | ||
1.2.2 | ||
===== | ||
* Added 'dbError' event | ||
* Call log function in 'error' event | ||
1.2.1 | ||
===== | ||
* Added 'error' event | ||
1.2.0 | ||
@@ -2,0 +13,0 @@ ===== |
@@ -53,2 +53,3 @@ /** | ||
* @param {MongoDb} db - The MongoDb database used to create the grid instance | ||
* @version 0.0.3 | ||
* | ||
@@ -61,2 +62,3 @@ */ | ||
* @param {File} file - The uploaded file | ||
* @version 0.0.3 | ||
* | ||
@@ -70,4 +72,14 @@ */ | ||
* @param {Object} config - The file configuration | ||
* @version 1.2.1 | ||
* | ||
*/ | ||
/** | ||
* Event emitted when the internal database connection emits an error | ||
* @event module:multer-gridfs-storage/gridfs~GridFSStorage#dbError | ||
* @param {Error} error - The error thrown by the database connection | ||
* @version 1.2.2 | ||
* | ||
*/ | ||
util.inherits(GridFSStorage, EventEmitter); | ||
@@ -127,2 +139,3 @@ | ||
self.emit('error', streamError, streamOpts); | ||
self._logError(streamError); | ||
cb(streamError); | ||
@@ -170,7 +183,3 @@ }); | ||
if (file.grid) { | ||
this.gfs.remove({_id: file.id}, onRemove.bind(this)); | ||
} else { | ||
return cb(null); | ||
} | ||
this.gfs.remove({_id: file.id}, onRemove.bind(this)); | ||
}; | ||
@@ -205,3 +214,6 @@ | ||
result = this[method](req, file, cb); | ||
this._handleResult(result, cb, false); | ||
// Avoid extra processing if we are dealing with callbacks | ||
if (result) { | ||
this._handleResult(result, cb, false); | ||
} | ||
} | ||
@@ -243,4 +255,4 @@ } catch (e) { | ||
value.then(onFullfill, onReject); | ||
} else if (isGen) { | ||
return cb(null, value); | ||
} else { | ||
cb(null, value); | ||
} | ||
@@ -305,2 +317,3 @@ }; | ||
if (err) { | ||
// We can't proceed if the connection fails | ||
throw err; | ||
@@ -312,3 +325,5 @@ } | ||
// although the docs specify each of the events has a MongoError argument | ||
self._logError(err || new Error()); | ||
var error = err || new Error(); | ||
self._logError(error); | ||
self.emit('dbError', error); | ||
} | ||
@@ -315,0 +330,0 @@ |
{ | ||
"name": "multer-gridfs-storage", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Multer storage engine for GridFS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
107
README.md
# Multer's GridFS storage engine | ||
[![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] ![Npm version][version-image] | ||
[![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] ![Npm version][version-image] ![Downloads][downloads-image] | ||
[GridFS](https://docs.mongodb.com/manual/core/gridfs) storage engine for [Multer](https://github.com/expressjs/multer) to store uploaded files directly to MongoDb | ||
@@ -53,15 +54,4 @@ | ||
Starting from version 1.1.0 the module function can be called with | ||
or without the javascript `new` operator like this | ||
or without the javascript `new` operator. | ||
```javascript | ||
var storage = require('multer-gridfs-storage')(options); | ||
var upload = multer({ storage: storage }); | ||
//or | ||
var GridFSStorage = require('multer-gridfs-storage'); | ||
var storage = new GridFSStorage(options) | ||
var upload = multer({ storage: storage }); | ||
``` | ||
The 1.2 version brings full support for promises and ES6 generators. | ||
@@ -74,32 +64,2 @@ You can check the [wiki][wiki] for more information. | ||
#### gfs | ||
Type: `object` or `Promise` | ||
Required if [`url`][url-option] option is not present | ||
The [gridfs-stream](https://github.com/aheckmann/gridfs-stream/) instance to use or a promise that resolves with the instance. | ||
If this option is provided, files are stored using this stream. This is useful when you have an existing GridFS object and want to reuse it to upload your files. | ||
Example: | ||
```javascript | ||
var Grid = require('gridfs-stream'); | ||
var mongo = require('mongodb'); | ||
var GridFSStorage = require('multer-gridfs-storage'); | ||
var db = new mongo.Db('database', new mongo.Server("127.0.0.1", 27017)); | ||
db.open(function (err) { | ||
if (err) return handleError(err); | ||
var gfs = Grid(db, mongo); | ||
var storage = GridFSStorage({ | ||
gfs: gfs | ||
}); | ||
var upload = multer({ storage: storage }); | ||
}) | ||
``` | ||
#### url | ||
@@ -153,2 +113,32 @@ | ||
#### gfs | ||
Type: `object` or `Promise` | ||
Required if [`url`][url-option] option is not present | ||
The [gridfs-stream](https://github.com/aheckmann/gridfs-stream/) instance to use or a promise that resolves with the instance. | ||
If this option is provided, files are stored using this stream. This is useful when you have an existing GridFS object and want to reuse it to upload your files. | ||
Example: | ||
```javascript | ||
var Grid = require('gridfs-stream'); | ||
var mongo = require('mongodb'); | ||
var GridFSStorage = require('multer-gridfs-storage'); | ||
var db = new mongo.Db('database', new mongo.Server("127.0.0.1", 27017)); | ||
db.open(function (err) { | ||
if (err) return handleError(err); | ||
var gfs = Grid(db, mongo); | ||
var storage = GridFSStorage({ | ||
gfs: gfs | ||
}); | ||
var upload = multer({ storage: storage }); | ||
}) | ||
``` | ||
#### filename | ||
@@ -403,2 +393,12 @@ | ||
- config: The failed upload configuration | ||
#### Event: `'dbError'` | ||
This event is emitted when there underlying connection emits an error. | ||
> Only available when the storage is created with the [`url`][url-option] option. | ||
*Event arguments* | ||
- error: The error emitted by the database connection | ||
@@ -423,5 +423,7 @@ ## Debugging | ||
If a function is provided it will be called in every log event with two arguments `err` y `log` with the error or | ||
the message respectively. The `log` object contains two properties `message` and `extra` corresponding to the | ||
event that triggered the log and any additional info, eg. the uploaded file | ||
the message respectively. | ||
The `log` object contains two properties `message` and `extra` corresponding to the | ||
event that triggered the log and any additional info, e.g. the uploaded file | ||
```javascript | ||
@@ -431,3 +433,3 @@ var storage = require('multer-gridfs-storage')({ | ||
log: function(err, log) { | ||
if (error) { | ||
if (err) { | ||
console.error(err); | ||
@@ -480,14 +482,2 @@ } else { | ||
In case you don't have mocha installed | ||
```bash | ||
$ npm install mocha -g | ||
``` | ||
and then run | ||
```bash | ||
$ mocha | ||
``` | ||
Code coverage thanks to [istanbul](https://github.com/gotwarlost/istanbul) | ||
@@ -508,2 +498,3 @@ | ||
[version-image]:https://img.shields.io/npm/v/multer-gridfs-storage.svg "Npm version" | ||
[downloads-image]: https://img.shields.io/npm/dm/multer-gridfs-storage.svg "Monthly downloads" | ||
@@ -510,0 +501,0 @@ [url-option]: #url |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44282
766
503