#org.postgresql.util.PSQLException: Large objects cannot be used in autocommit mode.

10 messages · Page 1 of 1 (latest)

glass venture
#

In code, this error occurs when writing a photo to the database. How to solve it?

class ImageController:

package com.example.web_start.controllers;

import com.example.web_start.models.Image;
import com.example.web_start.repositories.ImageRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.io.ByteArrayInputStream;

@RestController
@RequiredArgsConstructor
public class ImageController {
private final ImageRepository imageRepository;

@GetMapping("/images/{id}")
private ResponseEntity<?> getImageById(@PathVariable Long id){
    Image image = imageRepository.findById(id).orElse(null);
    return  ResponseEntity.ok()
            .header("fileName",image.getOriginalFileName())
            .contentType(MediaType.valueOf(image.getContentType()))
            .contentLength(image.getSize())
            .body(new InputStreamResource(new ByteArrayInputStream(image.getBytes())));
}

}

slender etherBOT
#

This post has been reserved for your question.

Hey @glass venture! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

glass venture
slender etherBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

glass venture
#

Still need help!

jolly stump
#

Also you have posted a bunch of code here without any real explanation to it. Also your exception log doesn't seem to contain the exception message you included in your title.

#

Probably worth reminding you of the tip: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.