简体   繁体   English

如何在springboot rest api后端应用程序中存储用户个人资料图片

[英]how to store user profile pictures in springboot rest api backend application

I am working in backend part with spring boot and rest api.我正在使用 spring 引导和 rest api 在后端部分工作。 I need to store user details in database.我需要将用户详细信息存储在数据库中。 The question is what is best approach to handle user profile pictures in the server.问题是在服务器中处理用户个人资料图片的最佳方法是什么。 how to use @POST AND @GET methods in that case?在这种情况下如何使用@POST AND @GET 方法?

Use POST to store the picture on the server, GET to receive it and display it to the user.使用POST将图片存储在服务器上,使用GET接收并显示给用户。

Update You could try something like this:更新您可以尝试这样的事情:

    @RequestMapping(value = "/api/image/save", method = RequestMethod.POST)
    public void addImage(@RequestBody Image image) {
        imageService.addImage(image);
    }

This is what you put inside your controller.这就是您放入 controller 中的内容。 Then you need an imageService -instance which stores the image in the database.然后,您需要一个imageService ,它将图像存储在数据库中。 And you have an Image -class that contains the image data (image comes in eg as a base64-encoded String).并且您有一个包含图像数据的Image类(图像以 base64 编码的字符串形式出现)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM