How to call a third-party API to upload pictures?
This is the back-end small class of the monastery. Each article is shared from
[background introduction] [knowledge analysis] [common problems] [solutions] [coding practice] [extended thinking] [more discussion] [References]
Eight aspects of in-depth analysis of back-end knowledge / skills. This article shares:
[how to call a third-party API to upload pictures?]
1. Background introduction
In the development process, whether it is a web page or an app, there will basically be business needs for image upload. The most typical is that users need to upload avatars after registering an account or upload ID photos when users verify. There are two ways to upload pictures in Java: one is to upload pictures using jsp + Servlet; One is to use JSP + controller to upload pictures. Basically, there are two forms of storage. Blob type pictures are directly stored in the database, or pictures are stored on the server and the path corresponding to the box is stored in the database. Most websites use the latter.
2. Knowledge analysis
What is the API?
API (Application Programming Interface) is some pre-defined functions, which aims to provide the ability for applications and developers to access a set of routines based on some software or hardware without accessing the source code or understanding the details of the internal working mechanism
Alibaba cloud OSS
Alibaba cloud object storage service Object storage service (OSS) is a massive, secure, low-cost and highly reliable cloud storage service provided by Alibaba cloud. You can upload and download data in any application, anytime and anywhere by calling the API, or simply manage the data through the web console. OSS is suitable for storing any type of files and is suitable for various websites and development enterprises For Industry and developers.
multipartfile
(1) File uploaded in form Mata mode in HTML
(2) Only binary files and file names are stored
Upload process
(1) Use multipartfile class to receive uploaded pictures;
(2) Store the picture on the server (alicloud OSS) and return a picture path;
(3) The picture path is stored in the user information for calling.
3. Frequently asked questions
Make some restrictions on uploaded pictures
Generate thumbnails?
6. Expand thinking
6. Expand thinking
7. References
https://blog.csdn.net/baidu_38990811/article/details/78413470
https://blog.csdn.net/haluoluo211/article/details/52080325
https://www.cnblogs.com/xx0405/p/5653115.html
1. How to generate thumbnails
Set parameters after picture connection
format
http://bucket. /object? x-oss-process=image/action,parame_ value
Specify the mode of the thumbnail:
2. Alicloud file upload method
File upload, file stream upload, network stream upload
3. Anti theft chain function
In order to prevent the data on the OSS from being stolen by others, the OSS supports the anti-theft chain method based on the header field referer in the HTTP header.
Ppt link video link