Программисты JAVA общаются здесь
Anonymous
413 Запрос сущности слишком большой весенний ботинок
Сообщение
Anonymous » 02 фев 2025, 11:25
Я создавал конечную точку, в которую можно было бы загрузить многочисленные файлы до 50 МБ, но бросает слишком большую ошибку для запроса 413. Эта ошибка для файла 28 МБ, но я установил максимальный размер на 50 МБ < /p>
application.properties:
Код: Выделить всё
spring.application.name=pgm
# multipart config
# enable multipart uploads
spring.servlet.multipart.enabled=true
# max file-size
spring.servlet.multipart.max-file-size=50MB
logging.level.org.springframework.web=DEBUG
server.tomcat.max-swallow-size=50MB
< /code>
Файл основного приложения: < /p>
package com.mono.pgm;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class PgmApplication
{
public static void main(String[] args)
{
SpringApplication.run(PgmApplication.class, args);
}
}
< /code>
контроллер: < /p>
package com.mono.pgm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@RestController
public class controller
{
@Autowired
private fileUploadhelper helper;
@GetMapping("/")
public String hi()
{
return "hi!";
}
@PostMapping("/upload-file")
public ResponseEntity uploadFile(@RequestParam("theoneofall") MultipartFile file)
{
for(int i=0; i
класс загрузки: < /p>
package com.mono.pgm;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.FileOutputStream;
import java.io.InputStream;
@Component
public class fileUploadhelper
{
public String uploadDir = "C:\\Users\\comma\\Desktop\\projects\\pgm\\src\\main\\resources\\static\\images";
public boolean uploadFile(MultipartFile file)
{
boolean f = false;
try{
InputStream is = file.getInputStream();
byte[] data = new byte[is.available()];
is.read(data);
FileOutputStream fos = new FileOutputStream(uploadDir + "\\" + file.getOriginalFilename());
fos.write(data);
fos.flush();
fos.close();
f=true;
// Files.copy(file.getInputStream, Paths.get(uploadDir+"\\"+file.getOriginalName()),StandardCopyOption.ReplaceExisting);
}catch(Exception e){
e.printStackTrace();
}
return f;
}
}
Я спросил GPT об этом, и он сказал мне, что это могло произойти из -за некоторого максимального ограничения в Tomcat, я попробовал это, но не работал
Подробнее здесь:
https://stackoverflow.com/questions/794 ... pring-boot
1738484754
Anonymous
Я создавал конечную точку, в которую можно было бы загрузить многочисленные файлы до 50 МБ, но бросает слишком большую ошибку для запроса 413. Эта ошибка для файла 28 МБ, но я установил максимальный размер на 50 МБ < /p> application.properties: [code]spring.application.name=pgm # multipart config # enable multipart uploads spring.servlet.multipart.enabled=true # max file-size spring.servlet.multipart.max-file-size=50MB logging.level.org.springframework.web=DEBUG server.tomcat.max-swallow-size=50MB < /code> Файл основного приложения: < /p> package com.mono.pgm; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class PgmApplication { public static void main(String[] args) { SpringApplication.run(PgmApplication.class, args); } } < /code> контроллер: < /p> package com.mono.pgm; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @RestController public class controller { @Autowired private fileUploadhelper helper; @GetMapping("/") public String hi() { return "hi!"; } @PostMapping("/upload-file") public ResponseEntity uploadFile(@RequestParam("theoneofall") MultipartFile file) { for(int i=0; i класс загрузки: < /p> package com.mono.pgm; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; import java.io.FileOutputStream; import java.io.InputStream; @Component public class fileUploadhelper { public String uploadDir = "C:\\Users\\comma\\Desktop\\projects\\pgm\\src\\main\\resources\\static\\images"; public boolean uploadFile(MultipartFile file) { boolean f = false; try{ InputStream is = file.getInputStream(); byte[] data = new byte[is.available()]; is.read(data); FileOutputStream fos = new FileOutputStream(uploadDir + "\\" + file.getOriginalFilename()); fos.write(data); fos.flush(); fos.close(); f=true; // Files.copy(file.getInputStream, Paths.get(uploadDir+"\\"+file.getOriginalName()),StandardCopyOption.ReplaceExisting); }catch(Exception e){ e.printStackTrace(); } return f; } } [/code] Я спросил GPT об этом, и он сказал мне, что это могло произойти из -за некоторого максимального ограничения в Tomcat, я попробовал это, но не работал Подробнее здесь: [url]https://stackoverflow.com/questions/79406247/413-request-entity-too-large-spring-boot[/url]