Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle post data of size more than 2 mb

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

like image 431
javaMan Avatar asked Aug 12 '16 15:08

javaMan


People also ask

What is the size limit of a POST request?

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.

How much data we can send through POST method?

POST method does not have any limit on the size of data.

What is the maximum payload size for REST API?

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.


2 Answers

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)

like image 86
Konstantin Konyshev Avatar answered Oct 21 '22 10:10

Konstantin Konyshev


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.

like image 21
Duong Nguyen Avatar answered Oct 21 '22 09:10

Duong Nguyen