arnab layek
arnab layek

Reputation: 167

How to retrieve multiple blob images from database

Hi i am using Spring mvc and hibernate. I want to retrieve multiple blob images from database and want to display in jsp. I tried a lot but did not get fruitful answer. If anyone gives link or sample code then it would be great for me.

Upvotes: 0

Views: 1149

Answers (2)

Umapathi
Umapathi

Reputation: 568

i'm using server side this code it's works for me

Spring Controller

@RequestMapping(value ="/getImages", method = RequestMethod.GET)
    @ResponseBody
    public List<Product> getStateList(HttpServletResponse response, HttpServletRequest request) {
        List<Product> image = imageService.getImageList();
        List<Product> imageList= new ArrayList<Product>();
        for (Product m : new ArrayList<Product>(image)) {
            String base64Encoded = javax.xml.bind.DatatypeConverter.printBase64Binary(m.getImage());
            Product imagepath = new Product();
            imagepath.setImagePath(base64Encoded);
            imagepath.setItemName(m.getItemName());
            imageList.add(imagepath);
        } 
        return imageList;
    }

DAO

public List<Product> getImageList() {
        String getImageQuery = "FROM Product";
        Query query = sessionFactory.getCurrentSession().createQuery(getImageQuery);
        @SuppressWarnings("unchecked")
        List<Product> imgList = query.list();
        return imgList;
    }

Model Class

@Entity
@Table(name="imageUpload")
public class ImageUpload {

    @Id
    @Column(name="eloraId")
    private int eloraId;

    @Column(name="password")
    private String password;

    @Column(name="ownerName")
    private String ownerName;

    @Column(name="registeredId",columnDefinition="mediumblob")
    private byte[] registeredId;

    @Column(name="hospPanCard")
    private String hospPanCard;

    @Column(name="hospRegCert",columnDefinition="mediumblob")
    private byte[] hospRegCert;

    @Column(name="ownerPanCard",columnDefinition="mediumblob")
    private byte[] ownerPanCard;

    @Column(name="ownerselfDec",columnDefinition="mediumblob")
    private byte[] ownerselfDec;

    @Column(name="ownerAddProof",columnDefinition="mediumblob")
    private byte[] ownerAddProof;

    @Transient
    private String statusMessage;
}

Upvotes: 0

Waize
Waize

Reputation: 182

If you are already using spring you could also have a look at spring data and the data repositories (http://docs.spring.io/spring-data/commons/docs/current/reference/html/#repositories).
There are a lot examples out there how it should look in action :)
If you use the newest Version you can stream the results. With that you can load the images async if you have performance issues.

Upvotes: 1

Related Questions