I have json post data with below template
{
"themeId" : JSONString,
"themeName" : JSONString,
"tables" : [{
"tableName" : JSONString,
"records" : [{
"recordVersion" : JSONString,
"tableItems" : []
}]
}]
}
and on Java side I have REST API like this:
@POST
@Path("/{themeId}")
@Consumes({MediaType.APPLICATION_JSON})
public Response postTheme( @PathParam("themeId") String themeId, ThemeDictionary dictionary) throws InterruptedException {
//code to handle
}
It worked fine when post data is less than 2 MB but how to handle data size bigger than 2 MB.
Questions
1) Should I go with pagination.
2) If I split json into half then each half won't be valid json. So, should I accept strings and concatnate on server side?
3) Are there any good examples to handle this scenario
4) Looking for an approach that can handle json data of size less than or greater than 2 MB
The default value of the HTTP and HTTPS connector maximum post size is 2MB. However you can adjust the value as per your requirement. The below command to set the connector to accept maximum 100,000 bytes. If the http request POST size exceeds the 100,000 bytes then connector return HTTP/1.1 400 Bad Request.
POST method does not have any limit on the size of data.
REST API call limits The maximum payload limit for a single API call is 45 MB, so ensure that the aggregate size of the records in a request do not exceed this limit.
Pagination will not solve you problem since you are sending data to the server, and not receiving.
What servlet container do you use? It looks like default tomcat POST limit size.
If you are using standalone tomcat you need to set parameter maxPostSize for your Connector: see here or (here)
2MB is rather small and I think the approach to upload the json file as multipart, then normally process the json file can handle the up to 50MB sized file. An example of handling file uploading can be found here.
For json files that is more than hundred of MBs, we have to find some way to process in streaming, or split the file into smaller files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With