endpoint to upload and retrieve image in database using spring boot

Solutions on MaxInterview for endpoint to upload and retrieve image in database using spring boot by the best coders in the world

showing results for - "endpoint to upload and retrieve image in database using spring boot"
Marcel
04 Jun 2019
1<%@page contentType="text/html" pageEncoding="UTF-8"%>
2<!DOCTYPE html>
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6<title>JSP Page</title>
7</head>
8<body>
9<h1>Details are given below:</h1><hr>
10<table>
11<tr>
12<td>Id</td>
13<td>${id}</td>
14</tr>
15<tr>
16<td>Name</td>
17<td>${name}</td>
18</tr>
19<tr>
20<td>Image</td>
21<td><img src="data:image/jpg;base64,${image} alt="Girl in a jacket" style="width:50px;height:50px;"></img></td>
22</tr>
23</table>
24</body>
25</html>
26
Clarisse
28 Apr 2017
1package com.vasu.SpringBootFileUpload.Model;
2
3import javax.persistence.Column;
4import javax.persistence.Entity;
5import javax.persistence.GeneratedValue;
6import javax.persistence.GenerationType;
7import javax.persistence.Id;
8import javax.persistence.Lob;
9import javax.persistence.Table;
10
11/**
12 *
13 * @author Vasu Rajput
14 */
15@Entity
16@Table(name = "ImageProfile")
17public class MyModel {
18
19    @Id
20    @GeneratedValue(strategy = GenerationType.AUTO)
21    @Column(name = "Id")
22    private long id;
23
24    @Column(name = "Name")
25    private String name;
26
27    @Lob
28    @Column(name = "Image")
29    private byte[] image;
30
31    public MyModel() {
32        super();
33        // TODO Auto-generated constructor stub
34    }
35    public MyModel(String name, byte[] image) {
36        super();
37        this.name = name;
38        this.image = image;
39    }
40    public long getId() {
41        return id;
42    }
43    public void setId(long id) {
44        this.id = id;
45    }
46    public String getName() {
47        return name;
48    }
49    public void setName(String name) {
50        this.name = name;
51    }
52    public byte[] getImage() {
53        return image;
54    }
55    public void setImage(byte[] image) {
56        this.image = image;
57    }
58}
59
Abel
15 May 2016
1package com.vasu.SpringBootFileUpload.controller;
2
3import com.vasu.SpringBootFileUpload.Model.MyModel;
4import com.vasu.SpringBootFileUpload.Service.MyService;
5import java.util.Base64;
6import org.slf4j.Logger;
7import org.slf4j.LoggerFactory;
8import org.springframework.beans.factory.annotation.Autowired;
9import org.springframework.stereotype.Controller;
10import org.springframework.ui.Model;
11import org.springframework.web.bind.annotation.GetMapping;
12import org.springframework.web.bind.annotation.ModelAttribute;
13import org.springframework.web.bind.annotation.PathVariable;
14import org.springframework.web.bind.annotation.PostMapping;
15import org.springframework.web.bind.annotation.RequestBody;
16import org.springframework.web.bind.annotation.RequestParam;
17import org.springframework.web.bind.annotation.RestController;
18import org.springframework.web.multipart.MultipartFile;
19
20/**
21 *
22 * @author Vasu Rajput
23 */
24@Controller
25public class MyController {
26
27    private static final Logger logger = LoggerFactory.getLogger("MyController.class");
28    @Autowired
29    private MyService myService;
30
31    @GetMapping("/")
32    public String test() {
33        return "index";
34    }
35
36    @PostMapping("/fileupload")
37    public String fileUpload(@RequestParam("name") String name, @RequestParam("file") MultipartFile file) {
38        try {
39            logger.info("Name= " + name);
40            byte[] image = file.getBytes();
41            MyModel model = new MyModel(name, image);
42            int saveImage = myService.saveImage(model);
43            if (saveImage == 1) {
44                return "success";
45            } else {
46                return "error";
47            }
48        } catch (Exception e) {
49            logger.error("ERROR", e);
50            return "error";
51        }
52    }
53
54    @GetMapping("/getDetail/{id}")
55    public String getDbDetils(@PathVariable String id, Model model) {
56        try {
57            logger.info("Id= " + id);
58            MyModel imagesObj = myService.getImages(Long.parseLong(id));
59            model.addAttribute("id", imagesObj.getId());
60            model.addAttribute("name", imagesObj.getName());
61            byte[] encode = java.util.Base64.getEncoder().encode(imagesObj.getImage());
62            model.addAttribute("image", new String(encode, "UTF-8"));
63            return "imagedetails";
64        } catch (Exception e) {
65            logger.error("Error", e);
66            model.addAttribute("message", "Error in getting image");
67            return "redirect:/";
68        }
69    }
70}
71
queries leading to this page
how to upload and retrive image with spring boot and angularimage upload and retrieve postgresql angularrestful api for upload and retrieve image url with spring boot and angularangular 9 open file after download springboot sql serveupload image in mysql using angularupload 10 images at time springbootgoogle drive type application in springboot with database with angular 8spring jdbc upload imagespring how to upload and control phototshow to upload image from angular to spring bootupload a reference picture to a profile spring boothow to pass image in api in spring bootspring boot api for uploading photosspring boot file uploadfile upload update delete system using spring bootupload photo using spring boot jpa samplerestful api for upload and retrieve image with spring bootupload image in database using spring bootuploading photos java mysqlspring boot api image upload and display androidretrieving informationm and storing it a text file spring boot upload image and store it as a file in angular 8image upload through crud in spring bootspring expose upload image folderspring boot get saved imageangular 8 fileupload 2bspringboot 2b sql serverupload image spring boot mongodb angular 9product and image rest api spring bootread txt and insert postgresql spring boot and angularupload and retrieve image from with product table wth spring boot and angularspring boot image uploadrestful api for upload and retrieve image url with spring boot handle product size color and images using spring bootimage upload in spring rest apiwhere can i store images using spring bootget image from user input and upload image in database in spring hibernateretrieve files from database and preview theme angular 9 spring bootspring boot user profile photo sqlspring boot upload image to databasestore and retrive document as a byte 5b 5d springboot examplehow to handle image in spring boot post apistore a person with their picture in database with spring boothow to get data from database in angular with 40getmappingangular upload document and post to spring bootupdate image by origanal name in spring boot jparead image from computer spring boothow to keep image metadata while sending image to spring boot server javarest load jpg spring bootphoto spring bootfetch photos from disk spring bootspring boot get file uri from databaseretriving and pre view files from database angular 2bspringbootupload image to database spring bootsave a product with uploading a picture using angular and spring bootstore images in a local folder in spring bootbest way to save images in sql with spring boothow to store image path in database using spring bootimage filetypes spring bootupload a picture code spring bootspring boot upload image databindingjava spring upload image to databaseupdate by image name in spring boot jpaimage upload spring apiendpoint to upload and retrieve image in database using spring boothow to upload image in spring bootspring boot upload and viewing photosangular 8 fileupload 2bspring boot 2b sql serverretrieve images from cloud to spring frameworkwhere to write code of image upload in spring bootspring angular upload fileubuntu tomcat store imagesspring boot explaination with imagesadding image contoller in spring boot mariadb angularstoring images in filesystem and returning url spring boothow to retrieve image from database using spring bootupload an image with spring boot and angularspring boot save image to a pathhow to replace same image in spring boot by jpaangular 9 file upload with spring boot and sql databasespring boot application saving imagespring boot store image in databaseimage upload spring boot and jpaspring boot photos files get image as file from spring bootinsert image in folder path in mysql database using angularstore files in project folder spring bootspring boot save image byte 5b 5d and get pathspring boot upload image and displayrest api for upload and retrieve image with byte 5b 5d spring boot and angularupload and retrieve image with byte 5b 5d in spring boot and save it into database where to store images spring boot rest apiretrive files from databse and preview them angular9 spring bootspring boot image array uplode by spring bootsaving photos in spring boothow to store image spring bootangular spring boot upload image for bloghow to check by database same image file in multipart spring bootstore image using jdbctemplateendpoint to upload and retrieve image in database using spring boot