Custom Multer options not applied on field
Expected behavior
I have a model with a watch function that should update a code field on every save.
Actual/Current behavior
When the code field is still empty this works perfectly, but when there's already a value in the code field, I get a Multer error saying my Field value is too long:
Error: Field value too long
app-dev | at makeError (/usr/src/app/node_modules/multer/lib/make-error.js:12:13)
app-dev | at abortWithCode (/usr/src/app/node_modules/multer/lib/make-middleware.js:79:22)
app-dev | at Busboy.<anonymous> (/usr/src/app/node_modules/multer/lib/make-middleware.js:85:34)
app-dev | at Busboy.emit (events.js:180:13)
app-dev | at Busboy.emit (/usr/src/app/node_modules/busboy/lib/main.js:38:33)
app-dev | at PartStream.onEnd (/usr/src/app/node_modules/busboy/lib/types/multipart.js:261:15)
app-dev | at PartStream.emit (events.js:185:15)
app-dev | at endReadableNT (_stream_readable.js:1106:12)
app-dev | at process._tickCallback (internal/process/next_tick.js:178:19)
Steps to reproduce the actual/current behavior
I pass the multer options in my Keystone init to increase max fieldSize according to this commit:
keystone.init({
'multer options' : {
'limits': {
'fieldSize': 25 * 1024 * 1024 // 25 Mb
}
}
});
I add my watch function in my model on to the code field:
var keystone = require('keystone');
var Types = keystone.Field.Types;
import { convertWFS } from './myUtils';
var Post = new keystone.List('Post', {
autokey: { path: 'slug', from: 'title', unique: true },
map: { name: 'title' }
});
Post.add({
title: { type: String, required: true },
geoServiceUrl: {
type: Types.Url,
label: 'Geo Service Url',
initial: true,
required: true
},
geoServiceData: {
label: 'Geo Service GeoJSON',
type: Types.Code,
language: 'json',
watch: true,
value: watchGeoServiceUrl
}
});
function watchGeoServiceUrl(callback) {
if (this.geoServiceUrl) {
const result = convertWFS(this.geoServiceUrl);
callback(null, result);
} else {
callback(null, '');
}
}
Post.register();
When I log the multer options in a pre save hook, it outputs the value correctly:
console.log(keystone.get('multer options')); // returns: { limits: { fieldSize: 26214400 } }
The code field is quit long (238000 lines), but it seems like the multer options are not being applied? Thanks!
Environment
| Software | Version |
|---|---|
| Keystone | 4.0.0 |
| Node.js | 9.3.0 |
| Browser | Chrome 70.0.3538.77 |
Any news on this one? This is really preventing me from properly saving items in the admin...
So in server/createApp.js the bindBodyParser is imported: https://github.com/keystonejs/keystone/blob/d34f45662eb359e2cb18b397f2ffea21f9883141/server/createApp.js#L103 In there the multer options are added to the uploads configuration: https://github.com/keystonejs/keystone/blob/eb7c1bb0dcea5040f1f13fd42624434223b5c66a/server/bindBodyParser.js#L15
And in lib/uploads the configuration is passed to multer: https://github.com/keystonejs/keystone/blob/eb7c1bb0dcea5040f1f13fd42624434223b5c66a/lib/uploads.js#L36
Is this configuration only used on file fields then and not on 'normal' fields like Text etc.?
Edit:
Also, setting handle uploads to false still gives me the same error (so I guess the built-in multer does not get disabled in my app):
keystone.init({
// ...
'handle uploads': false, // turns it off
});
I can also confirm that the error only appears when my text field value length exceeds the default fieldSize limit of 1 Mb (1048576).
The problem is not the initialization in server/bindBodyParser.js but the call in admin/server/app/createDynamicRouter.js where it is called without options.
uploads.configure(router); // should be called with the multer options
Unfortunately the dynamic router is responsible for CRUD operations which is why an initial file upload works without issues but saving text fields that exceed 1mb (the default multer/busboy restriction) time out with a MulterError: Field value too long
A simple solution would probably be to use the same config values in createDynamicRouter.