当前位置:网站首页>How to design a highly available and extended image storage function
How to design a highly available and extended image storage function
2022-06-24 08:10:00 【A more dreams a】
The article brief introduction
In this paper, a small e-commerce system is designed Picture storage Module analysis and summary , Share how to design a suitable image storage function .
Common image storage methods
In daily system design , It is inevitable that the picture function will be involved , For example, pictures of commodities 、 Article cover 、 User profile, etc . Create a picture field for the data in the normal way , This field stores the path of the file . As the format below :
Data number | Other fields | Picture field |
|---|---|---|
1 | ... | |
2 | ... |
There are good and bad points in the above data table design :
advantage :
- Simple storage , Users only need to upload pictures , Get a picture of url Just store it .
- Simple presentation , The client only needs to be based on the value of the field , Show it .
Inferiority :
- Weak expansibility , If we change the domain name of our pictures later , You need to replace the domain name in all the data .
- Weak multi picture scalability , If one piece of data has more than one picture , The stored value may be in this format . Picture path 1, Picture path 2,...., Picture path n. Although storage is simple , However, data format conversion is required in the presentation stage , You need to convert a string to an array format for circular processing .
- Waste storage resources , Suppose there is a picture a, I uploaded the user's Avatar once , I also uploaded the product pictures once , In this way, the same picture will be stored twice , Double the storage space .
- The first 2 Point refers to the path problem , You may think that I don't store specific domain name information in my picture , Store only the name of the picture , You can splice it when the client shows it .$domain = 'https://www.baidu.com/'; $imageArray = ['1.png', '2.png', '3.png', '4.png']; foreach ($imageArray as $value) { $domain .= $value; } The above method can avoid the domain name problem , But it is also inevitable to avoid the problem of storage mode . It is possible that qiniu cloud storage was used in the early stage of the system , The following applies to Alibaba cloud storage , Tencent cloud storage , This needs to deal with storage methods . Although it can also solve , But it makes the system design more complicated .
Optimization idea
According to the above question , We can think about it , If all the pictures of the system , All of them are made into a functional module , There's not a place that needs to involve pictures , To call the list data in this module , Get the picture of the system , Would this be better ?
Pictured above , Picture management function of wechat official account . On the left is the classification of pictures , On the right is the corresponding specific picture . Where we need to apply pictures , Go to get the corresponding picture data .
meanwhile , We also have an independent material library management , You can view all the pictures of the system , Easy to manage pictures .
The project design
The optimization idea mentioned , Let's create a separate image manager . How should we design the data sheet ? Here we will demonstrate the image management of wechat official account .
- First, we have a classification of pictures , At this time, you need a picture classification table (image_category).
- Next , We need to create a specific picture table (image), Used to store specific picture data .
- Image classification is mainly the name of classification 、 Sort 、 Creation time and other information .
- The picture information table stores more fields . With picture classification id、 Store domain name 、 The name of the picture 、 The image url、 Size of picture 、 Information such as the type of picture .
- Take a field in the table to store the domain name , When the client obtains the domain name and the name of the picture , Direct splicing is the completion path of an image .
- The size of the picture and the extension of the picture , It is convenient for us to display on the page later . Some systems may show the size of the image .
Summary of the plan
Through the design above , We can summarize the following advantages :
- Optimized image storage space , Avoid uploading the same picture multiple times , Occupy the storage space of the system .
- If different storage platforms are involved , We have a domain name field in the picture , Just splice the domain name and picture name . In the later stage, no matter how many storage platforms are changed , The system will not have any impact .
- It is convenient for the system to manage pictures , In this way, the pictures are stored independently , It is convenient to view all picture data of the system .
- Tables involving business data , You only need to associate the id that will do .
边栏推荐
- Upgrade Mysql to the latest version (mysql8.0.25)
- 第 3 篇:绘制三角形
- Bit operation
- Graphmae ---- quick reading of papers
- 模型效果优化,试一下多种交叉验证的方法(系统实操)
- On the H5 page, the Apple phone blocks the content when using fixed to locate the bottom of the tabbar
- [test development] first knowledge of software testing
- Écouter le réseau d'extension SWIFT (source)
- 开放合作,共赢未来 | 福昕鲲鹏加入金兰组织
- Chapter 3 curve graph of canvas
猜你喜欢

宝塔面板安装php7.2安装phalcon3.3.2

Swift 基础 闭包/Block的使用(源码)

Vulnhub靶机:BOREDHACKERBLOG_ CLOUD AV

Echart 心得 (一): 有关Y轴yAxis属性

软件工程导论——第二章——可行性研究

一文理解同步FIFO

Oracle advanced SQL qualified query

Cold thinking on the hot track: multiplier effect is the fundamental requirement of East West calculation
![Leetcode 515 find the leetcode path of the maximum [bfs binary tree] heroding in each row](/img/16/011ba3aef1315c39526daac7e3ec89.png)
Leetcode 515 find the leetcode path of the maximum [bfs binary tree] heroding in each row

没有专业背景,还有机会成为机器学习工程师吗?
随机推荐
软件工程导论——第二章——可行性研究
Keep one decimal place and two decimal places
Chapter 4 line operation of canvas
C# Lambda
没有专业背景,还有机会成为机器学习工程师吗?
Swift extension networkutil (network monitoring) (source code)
Phonics
Upgrade Mysql to the latest version (mysql8.0.25)
有关iframe锚点,锚点出现上下偏移,锚点出现页面显示问题.iframe的srcdoc问题
You get in Anaconda
Vulnhub target: boredhackerblog: social network
某问答社区App x-zse-96签名分析
GraphMAE----論文快速閱讀
Simple refraction effect
Graphmae - - lecture rapide des documents
Introduction to software engineering - Chapter 3 - Requirements Analysis
More than observation | Alibaba cloud observable suite officially released
Simple summary of lighting usage
Jenkins 太老了 试试它?云原生 CI/CD Tekton
Shader common functions