413 Anfrage Entität zu großJava

Java-Forum
Anonymous
 413 Anfrage Entität zu groß

Post by Anonymous »

Ich habe einen Endpunkt erstellt, zu dem man Multipart -Dateien bis 50 MB hochladen kann, aber die 413 -Anforderungsentität zu groß ist Dieser Fehler für 28 MB Datei, aber ich habe die maximale Größe auf 50 MB < /p>
Application.Properties:
festgelegt.

Code: Select all

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>
Die Haupt -App -Datei: < /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>
Der Controller: < /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
Klasse hochladen: < /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;
}
}

Ich habe GPT darüber gefragt, und es sagte mir, dass es möglicherweise aufgrund einer maxpostsize -Grenze in Tomcat geschehen ist, habe es versucht, aber nicht gearbeitet

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post