Closed ahornung-plan-b-gmbh closed 2 years ago
What exactly are "large JSON data"? So how large is large in your case?
It eems that body-parser has a default limit of 100kb ... yes this is not that much :-)
So the clean solution is to pass "limit" as option to https://github.com/ioBroker/ioBroker.rest-api/blob/master/lib/rest-api.js#L261
see https://github.com/expressjs/body-parser#limit
@GermanBluefox To what we should limit?
Perfect, many thanks for the quick answer! This was exactly for what I was looking for. In my case I tried to store approx. 500 Server objects from a JSON, each object has optional ≈ 15-20 extra attributes. The file itself has about 500kb.
It seems that the standard is 2097152 (not kb) characters, which is equivalent to 4 MB of Unicode string data.
PS: My problem with the permission denied error is also fixed now. I only had to enable the SSL encryption and now I can use a different user than the default admin. @GermanBluefox maybe you can add this info to the main README.md overview.
No, the defaukt is 100kb as shown on the page linked above. All fine ... also 4MB is small ... We need to decide what we set as limit ... but maybe 4MB is a good start? @GermanBluefox
My problem with the permission denied error is also fixed now. I only had to enable the SSL encryption and now I can use a different user than the default admin. @GermanBluefox maybe you can add this info to the main README.md overview.
I am not quite sure, that I understand you. Does it required to enable SSL to use other users but admin?
First I want to say thank you for the really cool swagger rest-api adapter. Under the existing admin user everything runs smoothly so far. With another new user (in admin group) I unfortunately get "error": "permissionError", but this is at the moment okay and will check this later. But I ran into another issue with my normal admin account.
The
PUT
command to create and update state objects is generally working, but when I try to write large JSON data with e.g. the Rest API command:setState(id, state)
- set state value with JSON object (e.g.{"val": 1, "ack": true}
)I get a 413 - Request Entity Too Large Error in my test case. As a quick workaround I commented in the file 'obroker.rest-api/node_modules/raw-body/index.js' the following parts:
Lines 157-163
/* if (limit !== null && length !== null && length > limit) { return done(createError(413, 'limit: ' + limit + 'length1: ' + length + 'request entity too large', { expected: length, length: length, limit: limit, type: 'entity.too.large' })) } */
Lines 262-272/* if (limit !== null && received > limit) { done(createError(413, 'request entity too large', { limit: limit, received: received, type: 'entity.too.large' })) } else if (decoder) { buffer += decoder.write(chunk) } else { buffer.push(chunk) } */
Without these checks I can write large JSON data successfully.Expected behavior
Now I would like to know why the check is necessary and if there is a better solution for it. Can I perhaps set the limit in the header during the HTTP request?
Versions: