51

I'm new to java spring rest, and I'm stuck with http request methods get and put, specifically with the code below. I have already managed to upload my entity (event) with an image file. However I can't do a get method without facing the following error. I'm thinking more of the get method of my controller which is missing something, because I get a result but with a weird content type.

Postman

GET http://localhost:8080/stem/events
Error: Maximum response size reached

Browser

[{"id":1,"title":"Indoor luchtkwaliteit = Frisse kop","description":"Met het meettoestel  Frisse Kop gaan we aan de slag. We ontwerpen en bouwen dit helemaal zelf! We leren over 3D-ontwerpen en gaan hier zelf mee aan de slag. ","startDate":null,"endDate":null,"startHour":null,"endHour":null,"image":{"id":1,"fileName":"frissekop.jpg","fileType":"image/jpeg","content":"/9j/4AAQSkZJRgABAQEASABIAAD/4S3eRXhpZgAATU0AKgAAAAgADAEPAAIAAAAGAAAAngEQAAIAAAAQAAAApAESAAMAAAABAAEAAAEaAAUAAAABAAAAtAEbAAUAAAABAAAAvAEoAAMAAAABAAIAAAEyAAIAAAAUAAAAxAE7AAIAAAABAAAAAAITAAMAAAABAAIAAIKYAAIAAAABAAAAAIdpAAQAAAABAAAA2IglAAQAAAABAAAgTAAAIGBDYW5vbgBDYW5vbiBFT1MgMjAwMEQAAAAASAAAAAEAAABIAAAAATIwMjA6MDg6MjEgMTM6MDI6MTcAACeCmgAFAAAAAQAAArKCnQAFAAAAAQAAArqIIgADAAAAAQACAACIJwADAAAAAQMgAACIMAADAAAAAQACAACIMgAEAAAAAQAAAyCQAAAHAAAABDAyMzCQAwACAAAAFAAAAsKQBAACAAAAFAAAAtaRAQAHAAAABAECAwCSAQAKAAAAAQAA

Could someone help me to implement Get and update based on the relationship between Image and Event?

@Entity
@Table(name = "events")
@Data
public class Event {
    @Id
    @GeneratedValue
    private Integer id;
    private String title;
    @Lob
    private String description;
 
    
    @OneToMany(mappedBy = "event",cascade = CascadeType.ALL,
            orphanRemoval = true)
    private List<Image> images=new ArrayList<>();
   
  

   


    public void addImage(Image image) {
        images.add(image);
          image.setEvent(this);
    }

    public void removeImage(Image image) {
        images.remove(image);
        image.setEvent(null);
    }


    }
} ```


@Entity
@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "images")
public class Image {
    @Id
    @GeneratedValue

    private Integer id;
    private String fileName;
    private String fileType;
    @Lob
    private  byte []content;
    @ManyToOne(fetch = FetchType.LAZY)
  
    private Event event;

}

// Controller
@RestController
  @CrossOrigin
  public class EventController {
    @Autowired
   private EventService eventService;
    @Autowired
    private ImageService imageService;


    @GetMapping("/events")
    public List<Event> getAllEvents() {

        return eventService.getAllEvents();
    }

    @GetMapping("/events/{id}")
    public Event getEvent(@PathVariable Integer id) {
        return eventService.getEvent(id);

    }


    @PostMapping("/events")
    public void addEvent(@RequestPart("event") Event event, @RequestPart("file")MultipartFile file) {
            imageService.uploadImage(event,file);
    //    eventService.addEvent(event);

    }

    @PutMapping("/events/{id}")
    public void updateEvent(@PathVariable Integer id, @RequestPart Event event) {

        eventService.updateEvent(id, event);

    }


    @DeleteMapping("/events/{id}")
    public void removeEvent(@PathVariable Integer id) {

        eventService.removeEvent(id);

    }

1 Answer 1

157

This is a Postman specific error and it is generated because there is a Max Response Size limit available in the settings. By default it is 50 MB. Which means, Postman will fail the request if the response size exceeds 50 MBs.

Since, you are receiving JSON data along with file part or file base64 string (base64 is usually around 30% larger in size of the actual file, you might want to check that as well), it is more likely to complain about response size exceeding the limit because default limit is 50 MB and files can be bigger than that.

You can change the value to desired by going in the Postman Settings under General and modifying the default value for Max response size in MB to your desired value in MBs. Or set it to 0 in case you want to download the response of any size.

Postman Setting for Max Response Size in MB

Sign up to request clarification or add additional context in comments.

5 Comments

Postman also has a Send and Download option under the Send split button that will bypass the Max response size in MB setting.
I still had the above issue even after setting "Max response size in MB" to 0 with a JSON response of 100MB. After that i was still getting the message "Maximum response size reached". Turns out i also needed to GZIP my response content. After adding "Accept-Encoding: gzip" and zipping the content i was now able to show the data in postman and getting 0 errors.
Can you help me?
I have the same problem like you
@JohanKoele, Having a JSON response of 100 MB seems too much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.