前端传输大量数据到后端并将其存入数据库(websocket即时通讯发送图片)

1.当POST请求提交的数据量过大时,就会产生错误。解决方法如下“

本地tomcat需在配置文件中配置maxPostSize=-1。
Springboot中,在application.yml配置文件中添加以下内容:

server:  
  tomcat:
    max-http-post-size: -1

`

2.数据库报错 2006 -Mysql server has gone away

找mysql目录下的my.ini配置文件,修改/加入以下代码
(修改)max_allowed_packet=40M
(加入)innodb_lock_wait_timeout=288000
(加入)interactive_timeout = 288000
在这里插入图片描述
my.ini是隐藏文件,要设置显示隐藏文件夹。一般在安装MySql的根目录里。如果不在就在\ProgramData\MySQL\MySQL Server 5.6 下

3.websocket设置可以传输大量数据

package com.ruoyi.project.system.chat.controller;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.util.WebAppRootListener;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class WebAppRootContext implements ServletContextInitializer {
    public void onStartup(ServletContext servletContext) throws ServletException {
        System.out.println("org.apache.tomcat.websocket.textBuffersSize");
        servletContext.addListener(WebAppRootListener.class);
        servletContext.setInitParameter("org.apache.tomcat.websocket.textBufferSize","10240000");
    }

}

版权声明:本文为qq_2453548221原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。