DWQA QuestionsCategory: Development ToolHow to upload user's Avatar and display it in the foreground of Java Web project?
zrjjokin asked 2 months ago

For example, after the user uploads the avatar, the image address is stored in the database. Is the address string similar to WEB-INF / image / a.jpg?

2 Answers
Coder's notes answered 2 months ago

Keep it simple
Directly transfer the file obtained from the form to the specified directory of the server, record the path to the database, and use nginx and other servers to preview the image directly or use Tomcat and other mapping directory when it needs to be displayed
Complex point
Use Alibaba’s OSS or seven cattle cloud and other image services to store and push, record the address, and then splice the address for display

AZmake answered 2 months ago

1. It is recommended that the image address only store the image name, and the path can be specified when it is used, so as to facilitate the migration of image resources.
2. The access path of the uploaded image is generally/resources/staticFor example/resources/static/images, which can be accessed throughhttps://imgs.developpaper.com/imgs/xxx.pngPath access.