Two forms of picture uploading

Source: Internet
Author: User

Long ago the single application project upload pictures are very simple, after uploading pictures in the controller layer set the path and save to a path on the server line, the database storage path address, and finally set a virtual path in Tomcat, many years ago, most of them did so.

However, with the technology update iterative, SOA, microservices, such practices will be eliminated, if it is distributed deployment or cluster environment, upload files to their respective servers, is not able to achieve unity, then use the image server, before I mentioned Fastdfs, This is a very useful file server, not much to say here. Each project uploaded images are unified by the file server to manage, then in a distributed environment or cluster environment, according to the assigned path to access the image can be obtained.

1, the use of File stream processing, this result can be used by the browser, iOS and Android calls, from Multiparthttpservletrequest to get Multipartfile objects, and finally call the file server interface upload can

2. Upload using base64

After cutting the picture can produce a bunch of Base64 string, this string is you want to upload the picture, as long as the string to the background to decode processing, and finally in the use of Fastdfs to upload the line

So what's the difference between these two ways?

1, access to the file stream image requires 2 HTTP requests, and BASE64 only need one time

2, file stream images can be accessed in any browser, and base64 some browsers do not support

3, base64 picture cannot be cached (cache whole page is another matter)

4, base64 encoded picture is relatively large, so it is generally used to make small pictures, such as head

Use:

File stream is used to upload large images, such as some advertising pictures ah, product pictures and so on

Base64 pictures can be used to upload a user's avatar, or a small logo, or a small icon, etc.

Base64 can be saved to the database, without the need to upload, but I do not recommend this, the picture should be unified in the file server management, of course, this look at the demand design

?

Two forms of picture uploading

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.