multer-gridfs-storage
Advanced tools
Comparing version 3.2.0 to 3.2.1
@@ -0,1 +1,5 @@ | ||
# 3.2.1 | ||
* Feature: Added `aliases` and `disableMD5` properties to file naming configuration | ||
# 3.2.0 | ||
@@ -2,0 +6,0 @@ |
@@ -39,2 +39,3 @@ /** | ||
bucketName: 'fs', | ||
aliases: null, | ||
}; | ||
@@ -289,2 +290,3 @@ | ||
if (this._legacy) { | ||
// `disableMD5` is not supported in GridStore | ||
settings = { | ||
@@ -295,2 +297,3 @@ chunk_size: opts.chunkSize, | ||
root: opts.bucketName, | ||
aliases: opts.aliases, | ||
}; | ||
@@ -305,2 +308,4 @@ gfs = new GridStore(this.db, opts.id, opts.filename, 'w', settings); | ||
metadata: opts.metadata, | ||
aliases: opts.aliases, | ||
disableMD5: opts.disableMD5, | ||
}; | ||
@@ -394,3 +399,3 @@ gfs = new GridFSBucket(this.db, {bucketName: opts.bucketName}); | ||
} else { | ||
return Promise.reject(new Error('Invalid type for file settings, got ' + setType)); | ||
throw new Error('Invalid type for file settings, got ' + setType); | ||
} | ||
@@ -433,9 +438,9 @@ }) | ||
// switched into flowing mode that causes the index not to be properly initialized so is better to open the store first | ||
store.open(function (error) { | ||
store.open((error) => { | ||
if (error) { | ||
return emitError(error); | ||
} | ||
writeStream.on('end', function () { | ||
writeStream.on('end', () => { | ||
store.close(function (err, f) { | ||
store.close((err, f) => { | ||
if (err) { | ||
@@ -519,4 +524,4 @@ return emitError(err); | ||
if (!fileSettings.filename) { | ||
promise = new Promise(function (resolve, reject) { | ||
crypto.randomBytes(16, function (err, buffer) { | ||
promise = new Promise((resolve, reject) => { | ||
crypto.randomBytes(16, (err, buffer) => { | ||
if (err) { | ||
@@ -533,3 +538,3 @@ return reject(err); | ||
return promise | ||
.then(function (prev) { | ||
.then((prev) => { | ||
// If no id is provided generate one | ||
@@ -543,5 +548,3 @@ // If an error occurs the emitted file information will contain the id | ||
}) | ||
.then(function (prev) { | ||
return Object.assign(prev, defaults, extra, fileSettings); | ||
}); | ||
.then((prev) => Object.assign(prev, defaults, extra, fileSettings)); | ||
}; | ||
@@ -548,0 +551,0 @@ |
{ | ||
"name": "multer-gridfs-storage", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "Multer storage engine for GridFS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -65,3 +65,3 @@ # Multer's GridFS storage engine | ||
The module returns a function that can be invoked to create a Multer storage engine. | ||
The module returns a function that can be invoked to create a Multer storage engine. It also works as a class so you can choose the best way to invoke it. | ||
@@ -180,4 +180,6 @@ Check the [wiki][wiki] for an in depth guide on how to use this module. | ||
By default, this module behaves exactly like the default Multer disk storage does. It generates a 16 bytes long name in hexadecimal format with no extension for the file to guarantee that there are very low probabilities of naming collisions. You can override this by passing your own function. | ||
This module uses [`GridFSBucket`](http://mongodb.github.io/node-mongodb-native/3.1/api/GridFSBucket.html) to store files in the database falling back to [`GridStore`](http://mongodb.github.io/node-mongodb-native/3.1/api/GridStore.html) in case the previous class is not found like, for example, in earlier versions of MongoDb. | ||
By default naming behaves exactly like the default Multer disk storage. A 16 bytes long name in hexadecimal format is generated with no extension for the file to guarantee that there are very low probabilities of collisions. You can override this by passing your own function. | ||
The return value of this function is an object or a promise that resolves to an object (this also applies to generators) with the following properties. | ||
@@ -193,4 +195,6 @@ | ||
`contentType` | The content type for the file (default: inferred from the request) | ||
`aliases` | Optional array of strings to store in the file document's aliases field (default: `null`) | ||
`disableMD5` | If true, disables adding an md5 field to file data (default: `false`, available only on MongoDb >= 3.1) | ||
Any missing properties will use the defaults. | ||
Any missing properties will use the defaults. Also note that each property must be supported by your installed version of MongoDb. | ||
@@ -280,3 +284,3 @@ If you return `null` or `undefined` from the file function, the values for the current file will also be the defaults. This is useful when you want to conditionally change some files while leaving others untouched. | ||
Each file in `req.file` and `req.files` contain the following properties in addition to the ones that Multer create by default. Most of them can be set using the [`file`][file-option] configuration. | ||
Each saved file located in `req.file` and `req.files` contain the following properties in addition to the ones that Multer create by default. Most of them can be set using the [`file`][file-option] configuration. | ||
@@ -504,3 +508,3 @@ Key | Description | ||
[connection-string]: https://docs.mongodb.com/manual/reference/connection-string | ||
[mongoclient-connect]: http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html | ||
[mongoclient-connect]: http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#.connect | ||
[mongo-db]: http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html | ||
@@ -507,0 +511,0 @@ [error-handling]: https://github.com/expressjs/multer#error-handling |
56879
991
514