CN111291207B - Picture storage method, device and server - Google Patents

Picture storage method, device and server Download PDF

Info

Publication number
CN111291207B
CN111291207B CN202010074907.8A CN202010074907A CN111291207B CN 111291207 B CN111291207 B CN 111291207B CN 202010074907 A CN202010074907 A CN 202010074907A CN 111291207 B CN111291207 B CN 111291207B
Authority
CN
China
Prior art keywords
picture
message digest
stored
database
data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010074907.8A
Other languages
Chinese (zh)
Other versions
CN111291207A (en
Inventor
范金乔
沈鹏
李国辉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Qianxin Technology Group Co Ltd
Secworld Information Technology Beijing Co Ltd
Original Assignee
Qianxin Technology Group Co Ltd
Secworld Information Technology Beijing Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Qianxin Technology Group Co Ltd, Secworld Information Technology Beijing Co Ltd filed Critical Qianxin Technology Group Co Ltd
Priority to CN202010074907.8A priority Critical patent/CN111291207B/en
Publication of CN111291207A publication Critical patent/CN111291207A/en
Application granted granted Critical
Publication of CN111291207B publication Critical patent/CN111291207B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/50Information retrieval; Database structures therefor; File system structures therefor of still image data
    • G06F16/51Indexing; Data structures therefor; Storage structures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/50Information retrieval; Database structures therefor; File system structures therefor of still image data
    • G06F16/53Querying

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Information Transfer Between Computers (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a picture storage method, a picture storage device, a server and a readable storage medium, and belongs to the technical field of picture processing. The picture storage method of the invention comprises the following steps: receiving a picture to be stored uploaded by terminal equipment through a first application program interface; calculating a first message digest of the picture to be stored through the first application program interface; judging whether a second message digest matched with the first message digest is stored in a preset database or not; if the second message digest is not stored in the database, storing the picture to be stored in the database, and returning the storage address of the picture to be stored to the terminal equipment; and if the second message digest is stored in the database, returning a storage address of the picture associated with the second message digest to the terminal equipment. The invention can save the storage space.

Description

Picture storage method, device and server
Technical Field
The present invention relates to the field of image processing, and in particular, to a method, an apparatus, and a server for storing images.
Background
In the prior art, when the user stores the pictures to the server, the situation that the same pictures are uploaded in disorder and repeated in a shorter period of time often occurs, or the uploaded pictures are repeated due to misoperation of the user, so that the service background repeatedly stores some pictures, pressure and unnecessary waste are caused to a storage space, and meanwhile, the picture inquiry and retrieval are complicated, so that the service performance is reduced.
Disclosure of Invention
An object of an embodiment of the invention is to provide a picture storage method, a device, a server and a computer readable storage medium, which are used for solving the problem that the existing server can repeatedly store some pictures, so that storage space is wasted.
The invention provides a picture storage method, which comprises the following steps:
receiving a picture to be stored uploaded by terminal equipment through a first application program interface;
calculating a first message digest of the picture to be stored through the first application program interface;
judging whether a second message digest matched with the first message digest is stored in a preset database or not;
if the second message digest is not stored in the database, storing the picture to be stored in the database, and returning the storage address of the picture to be stored to the terminal equipment;
and if the second message digest is stored in the database, returning a storage address of the picture associated with the second message digest to the terminal equipment.
Optionally, the calculating, by the first application program interface, the first message digest of the picture to be stored includes:
and calculating a first message digest of the picture to be stored by adopting an MD algorithm through the first application program interface.
Optionally, the MD algorithm is an MD5 algorithm.
Optionally, the calculating, by the first application program interface, the first message digest of the picture to be stored includes:
and calculating a first message digest of the picture to be stored by adopting an SHA algorithm through the first application program interface.
Optionally, the database is a mongo database, the data storage structure of the mongo database includes a picture ID field, a picture data field, and a message digest field, and the step of determining whether a second message digest matched with the first message digest is stored in the preset database includes:
searching data corresponding to the message digest field in the mongo database;
and judging whether a second message digest matched with the first message digest exists in the data corresponding to the message digest field.
Optionally, the picture storage method further includes:
receiving a picture query instruction sent by the terminal equipment through a second application program interface, wherein the picture query instruction comprises a storage address of a picture to be queried, and the storage address of the picture to be queried comprises a picture ID of the picture to be queried;
inquiring the picture to be inquired in the mongo database according to the picture ID;
When the picture to be queried is queried, picture data corresponding to the picture to be queried is returned to the terminal equipment, so that the terminal equipment displays the picture to be queried according to the picture data.
The invention also provides a picture storage device, which comprises:
the receiving module is used for receiving the pictures to be stored uploaded by the terminal equipment through the first application program interface;
the computing module is used for computing a first message digest of the picture to be stored through the first application program interface;
the judging module is used for judging whether a second message digest matched with the first message digest is stored in a preset database or not;
the storage module is used for storing the picture to be stored in the database if the second message digest is not stored in the database, and returning the storage address of the picture to be stored to the terminal equipment;
and the return module is used for returning the storage address of the picture associated with the second message digest to the terminal equipment if the second message digest is stored in the database.
Optionally, the database is a mongo database, and the data storage structure of the mongo database includes a picture ID field, a picture data field, and a message digest field, and the judging module is further configured to search the data corresponding to the message digest field in the mongo database; and the second message digest matched with the first message digest is used for judging whether the data corresponding to the message digest field exists or not.
The invention also provides a server, which comprises a memory, a processor and a computer program stored in the memory and capable of running on the processor, wherein the processor realizes the steps of the picture storage method when executing the computer program.
The present invention also provides a computer readable storage medium having stored thereon a computer program which when executed by a processor implements the steps of the picture storage method described above.
The beneficial effects of the technical scheme are that:
the embodiment of the invention receives the picture to be stored uploaded by the terminal equipment through the first application program interface; calculating a first message digest of the picture to be stored through the first application program interface; judging whether a second message digest matched with the first message digest is stored in a preset database or not; if the second message digest is not stored in the database, storing the picture to be stored in the database, and returning the storage address of the picture to be stored to the terminal equipment; and if the second message digest is stored in the database, returning a storage address of the picture associated with the second message digest to the terminal equipment. According to the embodiment of the invention, before the picture is stored in the database, the information abstract of the picture is calculated, so that whether the picture exists in the database or not can be determined according to the information abstract, and the picture is stored only when the picture does not exist in the database, and therefore the same picture can not be repeatedly stored, and the storage space is saved.
Drawings
FIG. 1 is a flowchart of an embodiment of a method for storing pictures according to the present invention;
FIG. 2 is a detailed flow chart of the steps of FIG. 1 for determining whether a second message digest matching the first message digest is stored in a predetermined database according to the present invention;
FIG. 3 is a flowchart illustrating another embodiment of a method for storing pictures according to the present invention;
FIG. 4 is a block diagram illustrating a program of an embodiment of a picture storage device according to an embodiment of the present invention;
FIG. 5 is a block diagram of a server according to an embodiment of the present invention.
Detailed Description
Advantages of the invention are further illustrated in the following description, taken in conjunction with the accompanying drawings and detailed description.
Reference will now be made in detail to exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numbers in different drawings refer to the same or similar elements, unless otherwise indicated. The implementations described in the following exemplary examples are not representative of all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with some aspects of the present disclosure as detailed in the accompanying claims.
The terminology used in the present disclosure is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. As used in this disclosure and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any or all possible combinations of one or more of the associated listed items.
It should be understood that although the terms first, second, third, etc. may be used in this disclosure to describe various information, these information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, first information may also be referred to as second information, and similarly, second information may also be referred to as first information, without departing from the scope of the present disclosure. The word "if" as used herein may be interpreted as "at … …" or "at … …" or "responsive to a determination", depending on the context.
In the description of the present invention, it should be understood that the numerical references before the steps do not identify the order in which the steps are performed, but are merely used to facilitate description of the present invention and to distinguish between each step, and thus should not be construed as limiting the present invention.
The embodiment of the invention provides a picture storage method. The picture storage method is applied to a server, wherein the server is preferably a picture bed server, and the picture bed server can be an independent server or a server cluster, such as a distributed system.
Referring to fig. 1, which is a flowchart illustrating a picture storing method according to an embodiment of the present invention, it will be understood that the flowchart in the embodiment of the method is not used to limit the order of executing steps.
As shown in fig. 1, the picture storage method includes steps S10 to S14, in which:
step S10, receiving a picture to be stored uploaded by terminal equipment through a first application program interface;
in particular, the terminal device may exist in a variety of forms including, but not limited to:
(1) A mobile communication device: such devices are characterized by mobile communication capabilities and are primarily aimed at providing voice, data communications. Such terminals include: smart phones (e.g., iPhone), multimedia phones, functional phones, and low-end phones, etc.
(2) Ultra mobile personal server: such devices are in the category of personal computers, having computing and processing functions, and generally also having mobile internet access characteristics. Such terminals include: PDA, MID, and UMPC devices, etc., such as iPad.
(3) Other electronic devices with data interaction function.
In this embodiment, the server provides a first application program interface (API, application ProgrammingInterface) for the terminal device to store the picture in the server through the first application program interface, that is, the first application program interface is an interface for storing the picture. The terminal equipment is provided with a corresponding application client or webpage client, and a user can store the pictures into the server through the application client or webpage client in the terminal equipment. When the terminal equipment is required to be stored in the server, the terminal equipment encapsulates the data of the picture to be stored according to the specification of the first application program interface, and then uploads the encapsulated picture data through the first application program interface, so that the server can receive the picture to be stored uploaded by the terminal equipment.
Step S11, calculating a first message digest of the picture to be stored through the first application program interface.
Specifically, the Message Digest (Message Digest) is also called a Digital Digest (Digital Digest). It is a fixed length value that uniquely corresponds to a message or text and results from the message digest algorithm acting on the message. If the message is changed en route, the recipient knows whether the message was changed by comparing the newly generated digest of the received message with the original digest. The message digest thus ensures the integrity of the message. In this embodiment, the message digest algorithm may be an MD algorithm, a SHA algorithm, a MAC (Message Authentication Code) algorithm, or the like.
After the server receives the picture to be stored uploaded by the terminal equipment, a first application program interface can be called to generate a message digest of picture data corresponding to the picture to be stored by adopting a message digest algorithm so as to obtain the first message digest.
In an embodiment, the calculating, by the first application program interface, the first message digest of the picture to be stored includes:
and calculating a first message digest of the picture to be stored by adopting an MD algorithm through the first application program interface.
Specifically, the MD (Message Digest) algorithm is a message digest algorithm, and can be classified into three algorithms of MD2, MD4 and MD5 according to the version of the specification, and the message digest generated by the MD algorithm is 128 bits. From the aspect of security, the security ranks of these three algorithms are MD5> MD4> MD2, so, in order to improve security, in this embodiment, the MD algorithm is preferably an MD5 algorithm, and when the first message digest is calculated by the MD5 algorithm, the first message digest may also be referred to as an MD5 value or an MD5 code.
In the embodiment of the invention, the first message abstract of the picture to be stored is calculated through the MD algorithm, so that whether the same picture exists in the database or not can be judged through abstract information, and the picture is prevented from being stored repeatedly.
In another embodiment, the calculating, by the first application program interface, the first message digest of the picture to be stored includes:
and calculating a first message digest of the picture to be stored by adopting an SHA algorithm through the first application program interface.
Specifically, the SHA (Secure Hash Algorithm ) algorithm is also an information digest algorithm, and the SHA family has five algorithms, SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512, respectively, with SHA-224, SHA-256, SHA-384, and SHA-512 collectively referred to as SHA-2. The number of bits of the message digest generated by the different SHA algorithms is different, e.g., 160 bits for the message digest generated by the SHA-1 algorithm and 224 bits for the message digest generated by the SHA-224 algorithm. In this embodiment, the specific SHA algorithm may be selected according to practical situations, for example, the SHA algorithm is SHA-256.
In the embodiment of the invention, the first message abstract of the picture to be stored is calculated by the SHA method, so that whether the same picture exists in the database or not can be judged through abstract information, and the picture is prevented from being stored repeatedly.
Step S12, judging whether a second message digest matched with the first message digest is stored in a preset database.
Specifically, the preset database is a database for storing pictures, the type of the database can be selected according to practical situations, for example, a Mongo database, a Redis database, a Memcache database, and the like, and in this embodiment, the database is preferably a Mongo database, which is a database based on distributed file storage and is written in c++ language. It is intended to provide a scalable high performance data storage solution for WEB applications.
In the embodiment of the present invention, the data stored in the database may be checked to determine whether a second message digest matching the first message digest is stored in the database, where the matching of the first message digest and the second message digest means that the second message digest stored in the database is identical to the first message digest, for example, the first message digest is abf, and if the second message digest stored in the database is abf, it indicates that the second message digest matching the first message digest exists in the database.
In an embodiment, the database is a mongo database, and the data storage structure of the mongo database includes a picture ID field, a picture data field, and a message digest field. The picture ID field is an identification for uniquely identifying one picture, the data of the ID fields corresponding to different pictures are different, and the picture can be conveniently inquired through the data of the ID fields; the data corresponding to the picture data field is picture data; the data corresponding to the message digest field is a number obtained by generating a message digest for the picture data. In other embodiments of the present invention, the data storage structure of the mongo database further includes a picture suffix field, where data corresponding to the field is used to distinguish a format of a picture, that is, whether the picture belongs to a picture in JPG format, a picture in png format, or other formats.
In this embodiment, referring to fig. 2, the step of determining whether a second message digest matched with the first message digest is stored in a preset database includes:
step S20, searching the data corresponding to the message digest field in the mongo database.
Step S21, judging whether a second message digest matched with the first message digest exists in the data corresponding to the message digest field.
Specifically, since the data storage structure in the mongo database contains the message digest field, the message digest of each picture stored in the database can be found by looking up the data corresponding to the message digest field in the database. Comparing the searched message digests of the pictures with the first message digest, and if the current searched message digest is the same as the first message digest, indicating that a second message digest matched with the first message digest exists; if the currently searched message digest is different from the first message digest, comparing the message digests of other searched pictures with the first message digest until the message digests which are the same as the first message digest are searched or the message digests of all pictures are compared, and ending the searching and comparing of the message digests to obtain a judging result.
In the embodiment of the invention, the data corresponding to the message digest field is searched in the mongo database, so that whether the second message digest matched with the first message digest exists or not can be rapidly judged.
And step S13, if the second message abstract is not stored in the database, storing the picture to be stored in the database, and returning the storage address of the picture to be stored to the terminal equipment.
Specifically, when the second message digest is not stored in the database, which indicates that there is no picture identical to the picture to be stored in the database, the server may store the data of the picture to be stored and allocate a storage address for storing the data of the picture to be stored in the database, where the storage address is a URL (Uniform Resource Locator ), and in an embodiment, the storage address includes a picture ID of the picture to be stored, so that the picture to be stored may be quickly found through the picture ID.
Step S14, if the second message digest is stored in the database, returning a storage address of the picture associated with the second message digest to the terminal device.
Specifically, when the second message digest is stored in the database, it indicates that the same picture as the picture to be stored exists in the database, and in order to avoid re-storing the picture, the server may discard the data of the picture to be stored, thereby saving storage space. Meanwhile, in order to facilitate the terminal device to query the picture associated with the second message digest, the server returns a storage address of the picture associated with the second message digest to the terminal device, so that the terminal device can query the picture through the storage address.
The embodiment of the invention receives the picture to be stored uploaded by the terminal equipment through the first application program interface; calculating a first message digest of the picture to be stored through the first application program interface; judging whether a second message digest matched with the first message digest is stored in a preset database or not; if the second message digest is not stored in the database, storing the picture to be stored in the database, and returning the storage address of the picture to be stored to the terminal equipment; and if the second message digest is stored in the database, returning a storage address of the picture associated with the second message digest to the terminal equipment. According to the embodiment of the invention, before the picture is stored in the database, the information abstract of the picture is calculated, so that whether the picture exists in the database or not can be determined according to the information abstract, and the picture is stored only when the picture does not exist in the database, and therefore the same picture can not be repeatedly stored, and the storage space is saved.
The embodiment of the invention provides another image storage method, which is based on the above embodiment, as shown in fig. 3, and further includes:
Step S30, receiving a picture query instruction sent by the terminal equipment through a second application program interface, wherein the picture query instruction comprises a storage address of a picture to be queried, and the storage address of the picture to be queried comprises a picture ID of the picture to be queried.
Specifically, the server provides a second application program interface (API, application Programming Interface) to the outside for the terminal device to query the picture from the server through the second application program interface, i.e. the first two-application program interface is an interface for querying the picture. The terminal equipment is provided with a corresponding application client or webpage client, and a user can send a picture query instruction to the server through the application client or the webpage client in the terminal equipment. When the picture is required to be inquired from the server, the terminal equipment encapsulates the data of the picture inquiry instruction according to the specification of the second application program interface, and then the encapsulated picture inquiry data is sent to the server through the second application program interface, so that the server can receive the picture inquiry instruction sent by the terminal equipment. In this embodiment, the picture query instruction includes a storage address of a picture to be queried, where the storage address includes a picture ID. In this embodiment, the storage address is a URL (UniformResource Locator ) of the picture to be stored, and the picture ID may be in the URL.
It should be noted that, the second application program interface in the present embodiment and the first application program interface in the above embodiment are preferably written in the golang language, and of course, in other embodiments of the present invention, the second application program interface may be written in other languages, such as C language, c++ language, and the like.
In the embodiment of the invention, the first application program interface and the second application program interface are written through the golang language, so that the server in the embodiment of the invention can be deployed on a single machine, and the method has the advantages of quick deployment and stable performance.
And S31, inquiring the picture to be inquired in the mongo database according to the picture ID.
Specifically, since the mongo storage structure in the mongo database for storing the picture data includes a picture ID field, the picture to be queried can be quickly found through the picture ID.
And step S32, when the picture to be queried is queried, returning picture data corresponding to the picture to be queried to the terminal equipment, so that the terminal equipment displays the picture to be queried according to the picture data.
Specifically, when the picture to be queried is found, the server returns the picture data corresponding to the picture to be queried to the terminal equipment, when the picture data is returned, the server adds Content-Type field data and Accept-Range field data in the picture data, wherein the field data is used for telling the Content Type of the picture Content actually returned by the terminal equipment, the Accept-Range field data is used for indicating whether the server supports a breakpoint request, if so, after the network of the terminal equipment is interrupted, the server can continue to acquire the rest data after the network is restored, and the data is never restarted.
After receiving the picture data returned by the server, the terminal equipment can display the picture according to the picture data.
In the embodiment of the invention, the picture is inquired through the picture ID, so that the picture inquiry efficiency can be improved.
Referring to fig. 4, a block diagram of a picture storage device 400 according to an embodiment of the invention is shown. The picture storage device 400 is applied to a server.
In this embodiment, the image storage device 400 includes a series of computer program instructions stored on a memory, which when executed by a processor, can implement the image storage function of the embodiments of the present invention. In some embodiments, the picture store 400 may be divided into one or more modules based on the particular operations implemented by portions of the computer program instructions. For example, in fig. 4, the picture storage device 400 may be divided into a receiving module 401, a calculating module 402, a judging module 403, a storing module 404, and a returning module 405. Wherein:
a receiving module 401, configured to receive a picture to be stored uploaded by a terminal device through a first application program interface;
in particular, the terminal device may exist in a variety of forms including, but not limited to:
(1) A mobile communication device: such devices are characterized by mobile communication capabilities and are primarily aimed at providing voice, data communications. Such terminals include: smart phones (e.g., iPhone), multimedia phones, functional phones, and low-end phones, etc.
(2) Ultra mobile personal server: such devices are in the category of personal computers, having computing and processing functions, and generally also having mobile internet access characteristics. Such terminals include: PDA, MID, and UMPC devices, etc., such as iPad.
(3) Other electronic devices with data interaction function.
In this embodiment, the server provides a first application program interface (API, application ProgrammingInterface) for the terminal device to store the picture in the server through the first application program interface, that is, the first application program interface is an interface for storing the picture. The terminal equipment is provided with a corresponding application client or webpage client, and a user can store the pictures into the server through the application client or webpage client in the terminal equipment. When the terminal device needs to be stored in the server, the terminal device encapsulates the data of the picture to be stored according to the specification of the first application program interface, and then uploads the encapsulated picture data through the first application program interface, so that the receiving module 401 of the server can receive the picture to be stored uploaded by the terminal device.
A calculating module 402, configured to calculate, through the first application program interface, a first message digest of the picture to be stored.
Specifically, the Message Digest (Message Digest) is also called a Digital Digest (Digital Digest). It is a fixed length value that uniquely corresponds to a message or text and results from the message digest algorithm acting on the message. If the message is changed en route, the recipient knows whether the message was changed by comparing the newly generated digest of the received message with the original digest. The message digest thus ensures the integrity of the message. In this embodiment, the message digest algorithm may be an MD algorithm, a SHA algorithm, a MAC (Message Authentication Code) algorithm, or the like.
After the receiving module 401 of the server receives the picture to be stored uploaded by the terminal device, the calculating module 402 may invoke the first application program interface to perform generation of a message digest on the picture data corresponding to the picture to be stored by adopting a message digest algorithm, so as to obtain the first message digest.
In an embodiment, the calculating module 402 is further configured to calculate, by using the first application program interface, a first message digest of the picture to be stored using an MD algorithm.
Specifically, the MD (Message Digest) algorithm is a message digest algorithm, and can be classified into three algorithms of MD2, MD4 and MD5 according to the version of the specification, and the message digest generated by the MD algorithm is 128 bits. From the aspect of security, the security ranks of these three algorithms are MD5> MD4> MD2, so, in order to improve security, in this embodiment, the MD algorithm is preferably an MD5 algorithm, and when the first message digest is calculated by the MD5 algorithm, the first message digest may also be referred to as an MD5 value or an MD5 code.
In another embodiment, the calculating module 402 is further configured to calculate, through the first application program interface, a first message digest of the picture to be stored using an SHA algorithm.
Specifically, the SHA (Secure Hash Algorithm ) algorithm is also an information digest algorithm, and the SHA family has five algorithms, SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512, respectively, with SHA-224, SHA-256, SHA-384, and SHA-512 collectively referred to as SHA-2. The number of bits of the message digest generated by the different SHA algorithms is different, e.g., 160 bits for the message digest generated by the SHA-1 algorithm and 224 bits for the message digest generated by the SHA-224 algorithm. In this embodiment, the specific SHA algorithm may be selected according to practical situations, for example, the SHA algorithm is SHA-256.
A determining module 403, configured to determine whether a second message digest that matches the first message digest is stored in a preset database.
Specifically, the preset database is a database for storing pictures, the type of the database can be selected according to practical situations, for example, a Mongo database, a Redis database, a Memcache database, and the like, and in this embodiment, the database is preferably a Mongo database, which is a database based on distributed file storage and is written in c++ language. It is intended to provide a scalable high performance data storage solution for WEB applications.
In this embodiment of the present invention, the determining module 403 may check the data stored in the database to determine whether a second message digest matching the first message digest is stored in the database, where the matching of the first message digest and the second message digest means that the second message digest stored in the database is identical to the first message digest, for example, the first message digest is abf, and if the second message digest stored in the database is abf, it indicates that the second message digest matching the first message digest exists in the database.
In an embodiment, the database is a mongo database, and the data storage structure of the mongo database includes a picture ID field, a picture data field, and a message digest field. The picture ID field is an identification for uniquely identifying one picture, the data of the ID fields corresponding to different pictures are different, and the picture can be conveniently inquired through the data of the ID fields; the data corresponding to the picture data field is picture data; the data corresponding to the message digest field is a number obtained by generating a message digest for the picture data. In other embodiments of the present invention, the data storage structure of the mongo database further includes a picture suffix field, where data corresponding to the field is used to distinguish a format of a picture, that is, whether the picture belongs to a picture in JPG format, a picture in png format, or other formats.
In this embodiment, the determining module 403 is further configured to search the mongo database for data corresponding to the message digest field; and the second message digest matched with the first message digest is used for judging whether the data corresponding to the message digest field exists or not.
Specifically, since the data storage structure in the mongo database contains the message digest field, the message digest of each picture stored in the database can be found by looking up the data corresponding to the message digest field in the database. Comparing the searched message digests of the pictures with the first message digest, and if the current searched message digest is the same as the first message digest, indicating that a second message digest matched with the first message digest exists; if the currently searched message digest is different from the first message digest, comparing the message digests of other searched pictures with the first message digest until the message digests which are the same as the first message digest are searched or the message digests of all pictures are compared, and ending the searching and comparing of the message digests to obtain a judging result.
And the storage module 404 is configured to store the picture to be stored in the database if the second message digest is not stored in the database, and return the storage address of the picture to be stored to the terminal device.
Specifically, when the second message digest is not stored in the database, which indicates that there is no picture identical to the picture to be stored in the database, the storage module 404 may store the data of the picture to be stored and allocate a storage address for storing the data of the picture to be stored in the database, where the storage address is a URL (Uniform Resource Locator ), and in an embodiment, the storage address includes a picture ID of the picture to be stored, so that the picture to be stored may be quickly found through the picture ID.
The storage module 404 is further configured to return, if the second message digest is stored in the database, a storage address of a picture associated with the second message digest to the terminal device.
Specifically, when the second message digest is stored in the database, it indicates that the same picture as the picture to be stored exists in the database, in order to avoid re-storing the picture, the storage module 404 may discard the data of the picture to be stored, thereby saving storage space. Meanwhile, in order to facilitate the terminal device to query the picture associated with the second message digest, the storage module 404 may also return the storage address of the picture associated with the second message digest to the terminal device, so that the terminal device may query the picture through the storage address.
The embodiment of the invention receives the picture to be stored uploaded by the terminal equipment through the first application program interface; calculating a first message digest of the picture to be stored through the first application program interface; judging whether a second message digest matched with the first message digest is stored in a preset database or not; if the second message digest is not stored in the database, storing the picture to be stored in the database, and returning the storage address of the picture to be stored to the terminal equipment; and if the second message digest is stored in the database, returning a storage address of the picture associated with the second message digest to the terminal equipment. According to the embodiment of the invention, before the picture is stored in the database, the information abstract of the picture is calculated, so that whether the picture exists in the database or not can be determined according to the information abstract, and the picture is stored only when the picture does not exist in the database, and therefore the same picture can not be repeatedly stored, and the storage space is saved.
Further, in an exemplary embodiment, the picture storage device 400 further includes: and a query module.
The receiving module 401 is further configured to receive a picture query instruction sent by the terminal device through the second application program interface, where the picture query instruction includes a storage address of a picture to be queried, and the storage of the picture to be queried includes a picture ID.
Specifically, the server provides a second application program interface (API, application Programming Interface) to the outside for the terminal device to query the picture from the server through the second application program interface, i.e. the first two-application program interface is an interface for querying the picture. The terminal equipment is provided with a corresponding application client or webpage client, and a user can send a picture query instruction to the server through the application client or the webpage client in the terminal equipment. When the picture needs to be queried from the server, the terminal equipment encapsulates the data of the picture query instruction according to the specification of the second application program interface, and then sends the encapsulated picture query data to the server through the second application program interface, so that the receiving module 401 of the server can receive the picture query instruction sent by the terminal equipment. In this embodiment, the picture query instruction includes a picture ID of a picture to be queried. In this embodiment, the picture query instruction includes a storage address of a picture to be queried, where the storage address includes a picture ID. In this embodiment, the storage address is a URL (Uniform ResourceLocator ) of the picture to be stored, and the picture ID may be in the URL.
It should be noted that, the second application program interface in the present embodiment and the first application program interface in the above embodiment are preferably written in the golang language, and of course, in other embodiments of the present invention, the second application program interface may be written in other languages, such as C language, c++ language, and the like.
In the embodiment of the invention, the first application program interface and the second application program interface are written through the golang language, so that the server in the embodiment of the invention can be deployed on a single machine, and the method has the advantages of quick deployment and stable performance.
And the query module is used for querying the picture to be queried in the mongo database according to the picture ID.
Specifically, since the mongo storage structure in the mongo database for storing the picture data includes a picture ID field, the picture to be queried can be quickly found through the picture ID.
The returning module 405 is further configured to, when the picture to be queried is queried, return picture data corresponding to the picture to be queried to the terminal device, so that the terminal device displays the picture to be queried according to the picture data.
Specifically, when the picture to be queried is found, the return module 405 returns the picture data corresponding to the picture to be queried to the terminal device, and when the picture data is returned, the return module 405 adds Content-Type field data and Accept-Range field data in the picture data, where the field data is used to tell the terminal device whether the Content Type of the picture Content actually returned is the same, and if so, the Accept-Range field data is used to indicate whether the server supports the breakpoint request, and if so, after the terminal device network is interrupted, the network can be restored to obtain the rest data, and the data can be obtained from never being restarted.
After receiving the picture data returned by the return module 405 of the server, the terminal device may display the picture according to the picture data.
In the embodiment of the invention, the picture is inquired through the picture ID, so that the picture inquiry efficiency can be improved.
Referring to fig. 5, a hardware architecture of the server 5 according to the present invention is shown. In the present embodiment, the server 5 is a device capable of automatically performing numerical calculation and/or information processing in accordance with a preset or stored instruction. Such as rack servers, blade servers, tower servers, or rack servers (including individual servers, or a server cluster made up of multiple servers), etc. As shown in fig. 5, the server 5 includes at least, but is not limited to: the memory 501, processor 502, and network interface 503 may be communicatively linked to each other by a system bus. Wherein:
the memory 501 includes at least one type of computer-readable storage medium including flash memory, hard disk, multimedia card, card memory (e.g., SD or DX memory, etc.), random Access Memory (RAM), static Random Access Memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 501 may be an internal storage module of the server 5, such as a hard disk or memory of the server 5. In other embodiments, the memory 501 may also be an external storage device of the server 5, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash Card (Flash Card) or the like, which are provided on the server 5. Of course, the memory 501 may also include both an internal memory module of the server 5 and an external memory device. In this embodiment, the memory 501 is generally used to store an operating system installed in the server 5 and various types of application software, such as program codes of a picture storage method. Further, the memory 501 may be used to temporarily store various types of data that have been output or are to be output.
The processor 502 may be a central processing unit (Central Processing Unit, simply CPU), controller, microcontroller, microprocessor, or other data processing chip in some embodiments. The processor 502 is typically used to control the overall operation of the server 5, such as performing control and processing related to data interaction or communication with the server 5, etc. In this embodiment, the processor 502 is configured to execute program codes or process data stored in the memory 501.
The network interface 503 may comprise a wireless network interface or a wired network interface, which network interface 503 is typically used to establish a communication link between the server 5 and other servers. For example, the network interface 503 is used to connect the server 5 to an external terminal through a network, establish a data transmission channel and a communication link between the server 5 and the external terminal, and the like. The network may be a wireless or wired network such as an Intranet (Intranet), the Internet (Internet), a global system for mobile communications (Global System of Mobile communication, abbreviated as GSM), wideband code division multiple access (Wideband Code Division Multiple Access, abbreviated as WCDMA), a 4G network, a 5G network, bluetooth (Bluetooth), wi-Fi, etc.
It should be noted that fig. 5 only shows a server with components 501-503, but it should be understood that not all of the illustrated components are required to be implemented and that more or fewer components may be implemented instead.
In this embodiment, the picture storing method stored in the memory 501 may also be divided into one or more program modules and executed by one or more processors (the processor 502 in this embodiment) to complete the present invention.
The present application provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the picture storage method of the embodiments. In this embodiment, the computer-readable storage medium includes a flash memory, a hard disk, a multimedia card, a card memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, and the like. In some embodiments, the computer readable storage medium may be an internal storage unit of a server, such as a hard disk or a memory of the server. In other embodiments, the computer readable storage medium may also be an external storage device of a server, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), etc. that are provided on the server. Of course, the computer-readable storage medium may also include both internal storage units of the server and external storage devices. In this embodiment, the computer-readable storage medium is generally used to store an operating system installed on a server and various types of application software, such as program codes of the picture storage method in the embodiment. Furthermore, the computer-readable storage medium may also be used to temporarily store various types of data that have been output or are to be output.
It will be apparent to those skilled in the art that the modules or steps of the embodiments of the invention described above may be implemented in a general purpose computing device, they may be concentrated on a single computing device, or distributed across a network of computing devices, they may alternatively be implemented in program code executable by computing devices, so that they may be stored in a storage device for execution by computing devices, and in some cases, the steps shown or described may be performed in a different order than what is shown or described, or they may be separately fabricated into individual integrated circuit modules, or a plurality of modules or steps in them may be fabricated into a single integrated circuit module. Thus, embodiments of the invention are not limited to any specific combination of hardware and software.
From the above description of embodiments, it will be apparent to those skilled in the art that the embodiments may be implemented by means of software plus a general purpose hardware platform, or may be implemented by hardware. Those skilled in the art will appreciate that all or part of the processes implementing the methods of the above embodiments may be implemented by a computer program for instructing relevant hardware, where the program may be stored in a computer readable storage medium, and where the program may include processes implementing the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read-only memory (ROM), a random access memory (RandomAccessMemory, RAM), or the like.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some or all of the technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.

Claims (9)

1. A picture storage method, comprising:
receiving a picture to be stored uploaded by terminal equipment through a first application program interface;
calculating a first message digest of the picture to be stored through the first application program interface;
judging whether a second message digest matched with the first message digest is stored in a preset database or not;
if the second message digest is not stored in the database, storing the picture to be stored in the database, and returning the storage address of the picture to be stored to the terminal equipment;
if the second message digest is stored in the database, returning a storage address of a picture associated with the second message digest to the terminal device;
The database is a mongo database, the data storage structure of the mongo database comprises a picture ID field, a picture data field and a message digest field, and the picture storage method further comprises the following steps:
receiving a picture query instruction sent by the terminal equipment through a second application program interface, wherein the picture query instruction comprises a storage address of a picture to be queried, and the storage address of the picture to be queried comprises a picture ID;
inquiring the picture to be inquired in the mongo database according to the picture ID;
when the picture to be queried is queried, picture data corresponding to the picture to be queried is returned to the terminal equipment, so that the terminal equipment displays the picture to be queried according to the picture data, wherein when the picture data is returned, a server is additionally provided with Content-Type field data and Accept-Range field data in the picture data, the Content-Type field data is used for telling the terminal equipment of the Content Type of the picture Content actually returned, and the Accept-Range field data is used for indicating whether the server supports breakpoint requests.
2. The picture storage method as claimed in claim 1, wherein the step of calculating the first message digest of the picture to be stored through the first application program interface includes:
And calculating a first message digest of the picture to be stored by adopting an MD algorithm through the first application program interface.
3. The picture storage method according to claim 2, wherein the MD algorithm is an MD5 algorithm.
4. The picture storage method as claimed in claim 1, wherein the step of calculating the first message digest of the picture to be stored through the first application program interface includes:
and calculating a first message digest of the picture to be stored by adopting an SHA algorithm through the first application program interface.
5. The picture storing method according to any one of claims 1 to 4, wherein the step of determining whether a second message digest matching the first message digest is stored in a preset database includes:
searching data corresponding to the message digest field in the mongo database;
and judging whether a second message digest matched with the first message digest exists in the data corresponding to the message digest field.
6. A picture storage device, comprising:
the receiving module is used for receiving the pictures to be stored uploaded by the terminal equipment through the first application program interface;
the computing module is used for computing a first message digest of the picture to be stored through the first application program interface;
The judging module is used for judging whether a second message digest matched with the first message digest is stored in a preset database or not;
the storage module is used for storing the picture to be stored in the database if the second message digest is not stored in the database, and returning the storage address of the picture to be stored to the terminal equipment;
a return module, configured to return, if the second message digest is stored in the database, a storage address of a picture associated with the second message digest to the terminal device;
the database is a mongo database, the data storage structure of the mongo database comprises a picture ID field, a picture data field and a message digest field, and the picture storage device comprises:
the receiving module is further configured to receive a picture query instruction sent by the terminal device through a second application program interface, where the picture query instruction includes a storage address of a picture to be queried, and the storage address of the picture to be queried includes a picture ID;
the judging module is further configured to query the picture to be queried in the mongo database according to the picture ID;
the return module is further configured to return, when the picture to be queried is queried, picture data corresponding to the picture to be queried to the terminal device, so that the terminal device displays the picture to be queried according to the picture data, where when the picture data is returned, the server is further configured to add Content-Type field data and Accept-Range field data in the picture data, where the Content-Type field data is used to tell the terminal device about a Content Type of a picture Content actually returned, and the Accept-Range field data is used to indicate whether the server supports a breakpoint request.
7. The picture storage device according to claim 6, wherein the judging module is further configured to search the mongo database for data corresponding to the message digest field; and the second message digest matched with the first message digest is used for judging whether the data corresponding to the message digest field exists or not.
8. A server comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the picture storage method of any one of claims 1 to 5 when the computer program is executed.
9. A computer-readable storage medium having stored thereon a computer program, characterized by: the computer program, when executed by a processor, implements the steps of the picture storage method of any one of claims 1 to 5.
CN202010074907.8A 2020-01-22 2020-01-22 Picture storage method, device and server Active CN111291207B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010074907.8A CN111291207B (en) 2020-01-22 2020-01-22 Picture storage method, device and server

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010074907.8A CN111291207B (en) 2020-01-22 2020-01-22 Picture storage method, device and server

Publications (2)

Publication Number Publication Date
CN111291207A CN111291207A (en) 2020-06-16
CN111291207B true CN111291207B (en) 2024-02-06

Family

ID=71025961

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010074907.8A Active CN111291207B (en) 2020-01-22 2020-01-22 Picture storage method, device and server

Country Status (1)

Country Link
CN (1) CN111291207B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113656618B (en) * 2021-08-12 2024-06-21 工银科技有限公司 Picture synchronization method and device, electronic equipment and readable storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101699822A (en) * 2009-08-06 2010-04-28 腾讯科技(深圳)有限公司 File uploading method and device, and mass storage system
CN105989532A (en) * 2015-02-28 2016-10-05 阿里巴巴集团控股有限公司 Data processing method and device
WO2017114190A1 (en) * 2015-12-30 2017-07-06 阿里巴巴集团控股有限公司 File uploading processing method and device
CN107015985A (en) * 2016-01-27 2017-08-04 阿里巴巴集团控股有限公司 A kind of data storage and acquisition methods and device
CN107306274A (en) * 2016-04-18 2017-10-31 北京市神州百戏文化产业有限公司 Data de-duplication method based on digital digest

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101699822A (en) * 2009-08-06 2010-04-28 腾讯科技(深圳)有限公司 File uploading method and device, and mass storage system
CN105989532A (en) * 2015-02-28 2016-10-05 阿里巴巴集团控股有限公司 Data processing method and device
WO2017114190A1 (en) * 2015-12-30 2017-07-06 阿里巴巴集团控股有限公司 File uploading processing method and device
CN107015985A (en) * 2016-01-27 2017-08-04 阿里巴巴集团控股有限公司 A kind of data storage and acquisition methods and device
CN107306274A (en) * 2016-04-18 2017-10-31 北京市神州百戏文化产业有限公司 Data de-duplication method based on digital digest

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
朱晓辉 ; 王杰华 ; 石振国 ; 陈苏蓉 ; .海量图片的分布式存储及负载均衡研究.计算机工程.2010,(23),全文. *

Also Published As

Publication number Publication date
CN111291207A (en) 2020-06-16

Similar Documents

Publication Publication Date Title
CN111756674B (en) Network communication method, system, device and computer readable storage medium
CN109391673B (en) Method, system and terminal equipment for managing update file
US11226944B2 (en) Cache management
CN112422702A (en) CDN back-to-source method, system and computer equipment
CN108491715B (en) Terminal fingerprint database generation method and device and server
CN112486915B (en) Data storage method and device
CN112839003A (en) Data verification method and system
CN111291207B (en) Picture storage method, device and server
CN113656098B (en) Configuration acquisition method and system
CN111580948A (en) Task scheduling method and device and computer equipment
CN111176706A (en) Terminal upgrading method and device, electronic equipment and storage medium
CN111259217A (en) Invoice archiving method and device and computer readable storage medium
CN106446138B (en) Data packet storage method and device
CN112969198A (en) Data transmission method, terminal and storage medium
CN111782244A (en) Configuration file updating method and device, computer equipment and storage medium
CN101170576A (en) A method, system and device for file upload
CN105610596B (en) Resource directory management method and network terminal
CN107908634B (en) Cache control method of browser and mobile terminal
CN114466004A (en) File transmission method, system, electronic equipment and storage medium
CN110377665B (en) Data synchronization method and device, electronic equipment and storage medium
CN109325057B (en) Middleware management method, device, computer equipment and storage medium
CN113806815A (en) File signing method and system
CN111190858A (en) Software information storage method, device, equipment and storage medium
CN110825406A (en) Software upgrading method and related equipment
CN113608817B (en) Method and system for processing bullet frame

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information
CB02 Change of applicant information

Address after: Room 332, 3 / F, Building 102, 28 xinjiekouwei street, Xicheng District, Beijing 100088

Applicant after: QAX Technology Group Inc.

Applicant after: Qianxin Wangshen information technology (Beijing) Co.,Ltd.

Address before: Room 332, 3 / F, Building 102, 28 xinjiekouwei street, Xicheng District, Beijing 100088

Applicant before: QAX Technology Group Inc.

Applicant before: LEGENDSEC INFORMATION TECHNOLOGY (BEIJING) Inc.

GR01 Patent grant
GR01 Patent grant