使用springboot在mongodb中保存图像URL

时间:2019-06-01 13:37:47

标签: mongodb spring-boot

@PutMapping("/gameslist")
    public ResponseEntity<gameslist> updategameslist(@Valid @RequestBody Gameslist gameslist,
            @RequestParam(value = "Name", defaultValue = "") String Name,
            @RequestParam(value = "Id", defaultValue = "") String Id) throws URISyntaxException {
        log.debug("REST request to update gameslist : {}", gameslist);
        if (gameslist.getId() == null) {
            throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
        }
        HttpHeaders headers = new HttpHeaders();
        headers.add("X-Name", Name);
        headers.add("X-Id", Id);
        System.out.println("******************=================> "+gameslist.getMy_image().length);

     byte[] bFile = new byte[(int) gameslist.getMy_image().length];


    int bytes = gameslist.getMy_image().length;
    Path path = Paths.get(UPLOADED_FOLDER + "File.JPG");
    System.out.println("paths is :"+path);
    try {
        Files.write(path, bFile);
        System.out.println("inside file");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }//@RequestParam("file") MultipartFile file

   // Gameslist result = null;

    Gameslist result = gameslist.save(gameslist);
    return ResponseEntity.ok()
            .headers(HeaderUtil.createUpdateAlert(ENTITY_NAME, gameslist.getid().toString()))
            .headers(headers).body(res);
}

@PutMapping("/gameslist")
    public ResponseEntity<gameslist> updategameslist(@Valid @RequestBody Gameslist gameslist,
            @RequestParam(value = "Name", defaultValue = "") String Name,
            @RequestParam(value = "Id", defaultValue = "") String Id) throws URISyntaxException {
        log.debug("REST request to update gameslist : {}", gameslist);
        if (gameslist.getId() == null) {
            throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
        }
        HttpHeaders headers = new HttpHeaders();
        headers.add("X-Name", Name);
        headers.add("X-Id", Id);
        System.out.println("******************=================> "+gameslist.getMy_image().length);

         byte[] bFile = new byte[(int) gameslist.getMy_image().length];


        int bytes = gameslist.getMy_image().length;
        Path path = Paths.get(UPLOADED_FOLDER + "File.JPG");
        System.out.println("paths is :"+path);
        try {
            Files.write(path, bFile);
            System.out.println("inside file");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }//@RequestParam("file") MultipartFile file

       // Gameslist result = null;

        Gameslist result = gameslist.save(gameslist);
        return ResponseEntity.ok()
                .headers(HeaderUtil.createUpdateAlert(ENTITY_NAME, gameslist.getid().toString()))
                .headers(headers).body(res);
    }

im无法在mongodb中将图像另存为url。请帮助

0 个答案:

没有答案