Image upload-Download-delete some experience summary of picture management

Source: Internet
Author: User

picture upload function is very common, many people think this function is very simple, with the improvement of requirements, this picture small system is really complex ah.
Demand 1: Upload, unfinished to achieve "large capacity storage", "Load Balancing", "Good performance", "technical content" and other requirements, the use of Fastdfs.   Note: Fastdfs is an open-source, lightweight, distributed file system that manages files.   Features include: file storage, file synchronization, file access (file upload, file download), etc., to solve the problem of large-capacity storage and load balancing.      Especially suitable for file-based online services, such as photo album sites, video sites and so on. Upload, think is just an "upload" function, think about it, not the Oh ~ Upload, you need to consider those temporary or no longer use the picture.Scenario 1: temporary, but no subsequent action. For example, the user chose a new avatar, try to preview the effect, but finally did not save, directly left the site.WORKAROUND: If you use Fastdfs, you can upload it to the database and make a mark.After you save it, the status is updated. At the appropriate time, check the status, the status of inappropriate images deleted, physical deletion.Scenario 2: Temporary, with follow-up action. This is the comparison scenario.
 Scenario 3: Previous, need to delete. For example, the user saves a new avatar.The previous avatar can be physically deleted, or it can be tombstoned. Requirement 2: Display and download. Can be configured in Nginx, Fastdfs.
  Requirement 3: DeleteSome pictures that may not be needed to be able to delete.The FASTDFS has an interface available.2 Different Solutions Single Business ScenarioUser upload Avatar, is one of the 1 business scenarios, but also a relatively simple scenario.   Typically, a user's avatar is a graph. In the actual situation, there are still multiple graphs.   Project projects, for example, can have multiple images.   When uploading, you can have multiple graphs.   When adding project projects, you can insert all of the graphs directly.      However, when updating project projects, you need to differentiate between insert, UPDATE, Delete3.     A. Mark out images that are no longer in use, and if they are tombstone, you can physically delete them later.   If it is physically deleted, kill it directly.      B. Updates are required.   Updated by ID. C. needs to be inserted. How to find these 3 kinds of graphs? Add: All inserts are updated: INSERT, UPDATE, delete may have input: when saving, pass over N graph, assume a set: A.png, C.png, D.png. The N-Map of the database, assumed to be a collection of B: A.png, B.png, c.pngDelete:b the element in the collection, not in a, the result is b.png (how the high school math collection is represented) Update: There are elements in both A and B, a.png,b.pngInsert: An element in a, but not in B, c.png,d.png Multiple business ScenariosGeneral system, there will be a number of places to use the picture, such as user picture, user album, Project pictures and so on.For each business scenario, consider the increase-modify-delete operation of the picture.I think it is possible to adopt a holistic approach.2 steps.The 1th step: When uploading the image, only do the insert operation, the previous picture marked as "deleted."or partial insert, partial update.2nd step: Identify those images that need to be deleted, physically deleted or tombstoned.All images uploaded, all through the Fastdfs, in theory can be found all the physical picture, this is the picture of the "complete" S.     If not, add the code that is stored in the database (a separate table) in the interface where the image is uploaded. Count all business scenarios that are being used by the picture collection U, the tombstone Picture Collection v.Create a new table P:A. Delete the logic in the Set V, distributed in multiple tables of picture data, unified into the P-table.B.s-u-v, is all the physical deletion of the picture data, unified into the P-table. such as the temporary upload of this image.Finally, to the operator 1 Unified Picture Delete interface. Physically deleted, execute Fastdfs delete directly.The tombstone, the physical deletion, the physical deletion of the database table, Fastdfs delete.The above is a personal summary, in view of the actual situation, the use of a single business scenario.In fact, I would prefer to use a global solution for multiple business scenarios.

Ray Fansunion
October 26, 2015
Hubei-Wuhan-courtesy Gate
: fansunion
qq:240370818

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Image upload-Download-delete some experience summary of picture management

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.