Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring boot controller class is not taking data more than 2MB from HTML template #22724

Closed
HimanshuChugh2 opened this issue Aug 4, 2020 · 2 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@HimanshuChugh2
Copy link

HimanshuChugh2 commented Aug 4, 2020

Problem in short: i have a textbox in which i am entering 3 million characters long string value, and that string is not able to pass from html to controller.

problem in detail: i am making a blogging website, in which i am using QuillJs as text editor. So whatever i enter in QuillJs editor are the contents of editor, and these contents are represented by "delta" object which contains a json representation of the contents of the editor. so if i add an image in the editor, quill will create img tag and the src of that tag will be the base64 text which is converted by QuillJs.

so now i am taking QuillJS's delta object to save it to the database so that i can display it as it was edited.

i get the data of QuillJs by this: document.getElementById("datajso").value= JSON.stringify(quill.getContents());

here datajso is a String field which is mapped to "data" which is String object in my entity "CreateContent".

so when "datajso" contains data more than 2MB, it does not passes the data to controller, and the value it passes is NULL.
less than 2MB works fine, it passes less than 2MB data to controller and i can save it in database.

i am attaching my complete project in a zip file below;

how you can check the problem i am facing:

run the program: go to http://localhost:8080/creators/creating
you will see a text editor, in that editor insert an image of 1MB and click on "save delta" button to populate the textbox which is bind to the "data" of "CreateContent" entity, it will take 10 secs to populate the textbox as the text is large. after populating textbox, click on "submit" to save the large text to database.

it will be saved in database mysql.

now if you insert an image more than 1.8MB and click on "save delta" the text box will be populated, however after clicking on "submit" the data will not be saved in database.

after debugging i found out that the fields are getting null when i am sending data more than 2MB to controller.

for that i have researched on google and found that i need to enter this in main class

//	@Bean  
//    public TomcatServletWebServerFactory tomcatEmbedded() {  
//
//		TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();  
//
//        tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {  
//            if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {  
//                //-1 means unlimited  
//                ((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(100000000);  
//                
//                ((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSavePostSize(100000000);
//            }  
//        });  
//
//        return tomcat;  
//    }
//	
	

and tried entering this in application.properties file

server.tomcat.max-http-post-size=100000000
server.tomcat.max-swallow-size=100000000

both of the above are not working for me, i have been stuck on this problem for 1 and half week.

i am attaching my complete project in a zip file below;
"removed zip file"

The controller class, entity, and html you will need to check in this project is:
"ConfigurationClass" "CreatorsHomeController.java" "CreateContent.java" "CreateContentRepository.java" "creating-mode.html" "application.properties" other classes you simply can ignore.

please help me.

@mdeinum
Copy link
Contributor

mdeinum commented Aug 4, 2020

The property to use is server.tomcat.max-http-form-post-size so looks like the wrong property being used.

See https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#server-properties

@HimanshuChugh2
Copy link
Author

HI @mdeinum

Thank you so much, it works.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

4 participants