CN111291207A - Picture storage method and device and server - Google Patents
Picture storage method and device and server Download PDFInfo
- Publication number
- CN111291207A CN111291207A CN202010074907.8A CN202010074907A CN111291207A CN 111291207 A CN111291207 A CN 111291207A CN 202010074907 A CN202010074907 A CN 202010074907A CN 111291207 A CN111291207 A CN 111291207A
- Authority
- CN
- China
- Prior art keywords
- picture
- stored
- database
- message digest
- message
- 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.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 38
- 238000004422 calculation algorithm Methods 0.000 claims description 59
- 241001178520 Stomatepia mongo Species 0.000 claims description 18
- 238000004590 computer program Methods 0.000 claims description 13
- 238000013500 data storage Methods 0.000 claims description 12
- 238000004364 calculation method Methods 0.000 claims description 5
- 238000004891 communication Methods 0.000 description 5
- 230000006870 function Effects 0.000 description 5
- 238000010295 mobile communication Methods 0.000 description 5
- 238000010586 diagram Methods 0.000 description 4
- 230000003993 interaction Effects 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 3
- 230000008569 process Effects 0.000 description 3
- 230000003068 static effect Effects 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 230000010365 information processing Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000004044 response Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 239000002699 waste material Substances 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/50—Information retrieval; Database structures therefor; File system structures therefor of still image data
- G06F16/51—Indexing; Data structures therefor; Storage structures
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/50—Information retrieval; Database structures therefor; File system structures therefor of still image data
- G06F16/53—Querying
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 Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Information Transfer Between Computers (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 comprises the following steps: receiving a picture to be stored uploaded by a terminal device through a first application program interface; calculating a first message abstract 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; 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; and if the second message abstract is stored in the database, returning the storage address of the picture associated with the second message abstract to the terminal equipment. The invention can save the storage space.
Description
Technical Field
The present invention relates to the field of picture processing, and in particular, to a picture storage method, device and server.
Background
However, in the prior art, when a user stores a picture in the server, the situation that the same picture is repeatedly uploaded in an unordered manner within a short time period often occurs, or the uploaded picture is repeated due to misoperation of the user, so that some pictures are repeatedly stored in a service background, pressure and unnecessary waste are caused to a storage space, and meanwhile, the picture query and retrieval are tedious, so that the service performance is reduced.
Disclosure of Invention
The embodiment of the invention aims to provide a picture storage method, a picture storage device, a server and a computer readable storage medium, which are used for solving the problem that storage space is wasted due to the fact that some pictures are repeatedly stored in an existing server.
The invention provides a picture storage method, which comprises the following steps:
receiving a picture to be stored uploaded by a terminal device through a first application program interface;
calculating a first message abstract 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;
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;
and if the second message abstract is stored in the database, returning the storage address of the picture associated with the second message abstract 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 the first message abstract 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 logo database, a data storage structure of the logo 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 matching 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;
and when the picture to be inquired is inquired, returning the picture data corresponding to the picture to be inquired to the terminal equipment so that the terminal equipment displays the picture to be inquired according to the picture data.
The present invention also provides a picture storage device, comprising:
the receiving module is used for receiving the picture to be stored uploaded by the terminal equipment through the first application program interface;
the calculation module is used for calculating a first message abstract of the picture to be stored through the first application program interface;
the judging module is used for judging whether a second message abstract matched with the first message abstract is stored in a preset database;
the storage module is used for 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 abstract is not stored in the database;
and the return module is used for returning the storage address of the picture associated with the second message abstract to the terminal equipment if the second message abstract is stored in the database.
Optionally, the database is a monog database, a data storage structure of the monog database includes a picture ID field, a picture data field, and a message digest field, and the determining module is further configured to search for data corresponding to the message digest field in the monog database; and the message digest judging module is used for judging whether a second message digest matched with the first message digest exists in the data corresponding to the message digest field.
The invention also provides a server, which comprises a memory, a processor and a computer program which is stored on the memory and can run on the processor, wherein the processor realizes the steps of the image storage method when executing the computer program.
The invention also provides a computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the above-mentioned picture storage method.
The beneficial effects of the above technical scheme are that:
according to the embodiment of the invention, the picture to be stored uploaded by the terminal equipment through the first application program interface is received; calculating a first message abstract 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; 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; and if the second message abstract is stored in the database, returning the storage address of the picture associated with the second message abstract 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 can be determined according to the information abstract, and the picture is stored only when the picture does not exist in the database, so that the same picture can not be stored repeatedly, and the storage space is saved.
Drawings
FIG. 1 is a flowchart illustrating an embodiment of a method for storing pictures according to the present invention;
FIG. 2 is a flowchart detailing the steps of determining whether a second message digest matching the first message digest is stored in the predetermined database of FIG. 1 according to the present invention;
FIG. 3 is a flowchart illustrating another embodiment of a picture storing method according to the present invention;
FIG. 4 is a block diagram of a program of an embodiment of a picture storage device according to the present invention;
fig. 5 is an architecture diagram of a server according to an embodiment of the present invention.
Detailed Description
The advantages of the invention are further illustrated in the following description of specific embodiments in conjunction with the accompanying drawings.
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the exemplary embodiments below are not intended to represent all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure, as detailed in the appended 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 and all possible combinations of one or more of the associated listed items.
It is to be understood that although the terms first, second, third, etc. may be used herein to describe various information, such 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 "when … …" or "in response 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 of performing the steps, but merely serve to facilitate the description of the present invention and to distinguish 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, preferably a map bed server, which may 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 can be understood that the flowchart in the embodiment of the method is not used to limit the sequence of executing steps.
As shown in FIG. 1, the picture storing method includes steps S10-S14, wherein:
step S10, receiving a picture to be stored uploaded by the terminal equipment through the first application program interface;
specifically, the terminal device may exist in various forms, including but not limited to:
(1) a mobile communication device: such devices are characterized by mobile communications capabilities and are primarily targeted at providing voice, data communications. Such terminals include: smart phones (e.g., iphones), multimedia phones, functional phones, and low-end phones, among others.
(2) Ultra-mobile personal server: the equipment belongs to the category of personal computers, has calculation and processing functions and generally has the characteristic of mobile internet access. Such terminals include: PDA, MID, and UMPC devices, etc., such as ipads.
(3) And other electronic devices with data interaction functions.
In this embodiment, the server provides an Application Programming Interface (API) to the outside, so that the terminal device stores the picture in the server through the API, that is, the API is an interface for storing the picture. The terminal device is provided with a corresponding application client or a corresponding webpage client, and a user can store the picture in the server through the application client or the webpage client in the terminal device. When the terminal equipment needs to be stored in the server, the terminal equipment packages the data of the picture to be stored according to the specification of the first application program interface, and then uploads the packaged 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). Which is a fixed length value that uniquely corresponds to a message or text, that is generated by the message digest algorithm acting on the message. If the message has changed en route, the recipient knows whether the message has 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, an SHA algorithm, a mac (message Authentication code) algorithm, or the like.
After receiving the picture to be stored uploaded by the terminal device, the server can call the first application program interface to generate a message abstract of the picture data corresponding to the picture to be stored by adopting an information abstract algorithm so as to obtain the first message abstract.
In an embodiment, the calculating, by the first application program interface, the first message digest of the picture to be stored includes:
and calculating the first message abstract of the picture to be stored by adopting an MD algorithm through the first application program interface.
Specifically, the MD (message digest) algorithm is an information digest algorithm, and is divided into three algorithms, MD2, MD4, and MD5, according to the specification version, and the message digest generated by the MD algorithm is 128 bits. In terms of security, the security of the three algorithms is ranked as MD5> MD4> MD2, and therefore, in order to improve security, in the present embodiment, the MD algorithm is preferably the MD5 algorithm, and when the first message digest is calculated by the MD5 algorithm, the first message digest may also be referred to as MD5 value or MD5 code.
In the embodiment of the invention, the first message digest of the picture to be stored is calculated through an MD algorithm, so that whether the same picture exists in a database can be judged through digest information, and the picture is prevented from being stored repeatedly.
In another embodiment, said calculating, by said first application program interface, a first message digest of said picture to be stored comprises:
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 a message digest Algorithm, and the SHA family has five algorithms, SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512, respectively, where SHA-224, SHA-256, SHA-384, and SHA-512 are collectively referred to as SHA-2. The number of bits of the message digests generated by different SHA algorithms is different, such as 160 bits for the message digest generated by SHA-1 algorithm and 224 bits for the message digest generated by SHA-224 algorithm. In this embodiment, a specific SHA algorithm may be selected according to actual situations, for example, the SHA algorithm is SHA-256.
In the embodiment of the invention, the first message digest of the picture to be stored is calculated by an SHA method, so that whether the same picture exists in the database can be judged by the digest information, and the picture is prevented from being stored repeatedly.
Step S12, determining whether a preset database stores a second message digest matching the first message digest.
Specifically, the preset database is a database for storing pictures, and the type of the database may be selected according to actual situations, for example, the database is a Mongo database, a Redis database, a Memcache database, or the like. It is intended to provide an extensible high performance data storage solution for WEB applications.
In this embodiment of the present invention, 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 the same as the first message digest, for example, the first message digest is abf, and if the second message digest stored in the database is also abf, it indicates that the second message digest matching the first message digest exists in the database.
In one embodiment, the database is a mongo database, and a data storage structure of the mongo database comprises a picture ID field, a picture data field and a message digest field. The image ID field is an identifier for uniquely identifying one image, the data of the ID fields corresponding to different images are different, and the image can be conveniently inquired through the data of the ID field; the data corresponding to the picture data field is picture data; the data corresponding to the message digest field is a number obtained by performing message digest generation on the picture data. In other embodiments of the present invention, the data storage structure of the logo database further includes a picture suffix field, and the data corresponding to the field is used to distinguish the format of the 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 matching the first message digest is stored in the preset database includes:
and step S20, searching the corresponding data of the message digest field in the mongo database.
Step S21, determining whether a second message digest matching the first message digest exists in the data corresponding to the message digest field.
Specifically, since the data storage structure in the mongo database includes the message digest field, the message digest of each picture stored in the database can be found by searching the data corresponding to the message digest field in the database. Comparing the message digest of each searched picture with the first message digest, and if the currently 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, continuing to compare the searched message digests of other pictures with the first message digest until the same message digest as the first message digest is searched or the message digests of all the pictures are completely compared, ending the search and comparison of the message digests and obtaining a judgment result.
In the embodiment of the invention, the data corresponding to the message digest field is searched in the monogo database, so that whether the second message digest matched with the first message digest exists can be quickly judged.
Step S13, if the second message digest is not stored in the database, store the picture to be 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, it indicates that there is no picture in the database that is the same as the picture to be stored, 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 Uniform Resource Locator (URL), and in an embodiment, the storage address includes a picture ID of the picture to be stored, so that the picture to be stored can be found quickly through the picture ID.
Step S14, if the second message digest is stored in the database, returning the 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 storing the picture again, the server may discard the data of the picture to be stored, thereby saving the storage space. Meanwhile, in order to facilitate the terminal device to query the picture associated with the second message digest, the server returns the 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.
According to the embodiment of the invention, the picture to be stored uploaded by the terminal equipment through the first application program interface is received; calculating a first message abstract 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; 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; and if the second message abstract is stored in the database, returning the storage address of the picture associated with the second message abstract 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 can be determined according to the information abstract, and the picture is stored only when the picture does not exist in the database, so that the same picture can not be stored repeatedly, and the storage space is saved.
An embodiment of the present invention provides another picture storage method, which is based on the foregoing embodiment, and as shown in fig. 3, the method further includes:
step S30, receiving 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 the picture to be queried, and the storage address of the picture to be queried includes a picture ID of the picture to be queried.
Specifically, the server provides a second Application Programming Interface (API) to the outside for the terminal device to query the picture from the server through the second API, that is, the first and second API is an interface for querying the picture. The terminal device is provided with a corresponding application client or a corresponding webpage client, and a user can send the picture query instruction to the server through the application client or the webpage client in the terminal device. When the picture needs to be inquired from the server, the terminal device packages the data of the picture inquiry command according to the specification of the second application program interface, and then sends the packaged picture inquiry data to the server through the second application program interface, so that the server can receive the picture inquiry command sent by the terminal device. 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 resource 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 this embodiment and the first application program interface in the above embodiment are preferably written in the golang language, but of course, in other embodiments of the present invention, the second application program interface may also be written in other languages, for example, in the C language, the C + + language, and the like.
In the embodiment of the invention, the first application program interface and the second application program interface are written by the golang language, so that the server in the embodiment of the invention can be deployed on a single machine, and the invention has the advantages of rapid deployment and stable performance.
And step S31, inquiring the picture to be inquired in the mongo database according to the picture ID.
Specifically, since the logo storage structure for storing picture data in the logo database includes the picture ID field, the picture to be queried can be quickly found through the picture ID.
Step S32, when the picture to be inquired is inquired, returning the picture data corresponding to the picture to be inquired to the terminal equipment, so that the terminal equipment displays the picture to be inquired 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 device, and when the picture data is returned, the server further 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 the Content Type of the picture Content actually returned, and the Accept-Range field data is used to indicate whether the server supports the breakpoint request, and if so, after the network of the terminal device is interrupted, the server can continue to acquire the remaining data after recovering the network, and never needs to restart to acquire the data.
After receiving the picture data returned by the server, the terminal device 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 efficiency of inquiring the picture can be improved.
Fig. 4 is a block diagram of a program of an embodiment of a picture storage device 400 according to the present invention. The picture storage apparatus 400 is applied to a server.
In this embodiment, the picture storage device 400 includes a series of computer program instructions stored in a memory, and when the computer program instructions are executed by a processor, the picture storage function of the embodiments of the present invention can be realized. In some embodiments, picture storage device 400 may be divided into one or more modules based on the particular operations implemented by the portions of the computer program instructions. For example, in fig. 4, the picture storage apparatus 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:
the receiving module 401 is configured to receive a picture to be stored, which is uploaded by a terminal device through a first application program interface;
specifically, the terminal device may exist in various forms, including but not limited to:
(1) a mobile communication device: such devices are characterized by mobile communications capabilities and are primarily targeted at providing voice, data communications. Such terminals include: smart phones (e.g., iphones), multimedia phones, functional phones, and low-end phones, among others.
(2) Ultra-mobile personal server: the equipment belongs to the category of personal computers, has calculation and processing functions and generally has the characteristic of mobile internet access. Such terminals include: PDA, MID, and UMPC devices, etc., such as ipads.
(3) And other electronic devices with data interaction functions.
In this embodiment, the server provides an Application Programming Interface (API) to the outside, so that the terminal device stores the picture in the server through the API, that is, the API is an interface for storing the picture. The terminal device is provided with a corresponding application client or a corresponding webpage client, and a user can store the picture in the server through the application client or the webpage client in the terminal device. When the terminal device needs to be stored in the server, the terminal device packages the data of the picture to be stored according to the specification of the first application program interface, and then uploads the packaged 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). Which is a fixed length value that uniquely corresponds to a message or text, that is generated by the message digest algorithm acting on the message. If the message has changed en route, the recipient knows whether the message has 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, an 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 computing module 402 may call the first application program interface to generate a message digest of the picture data corresponding to the picture to be stored by using an information digest algorithm, so as to obtain the first message digest.
In an embodiment, the calculating module 402 is further configured to calculate a first message digest of the picture to be stored by using an MD algorithm through the first application program interface.
Specifically, the MD (message digest) algorithm is an information digest algorithm, and is divided into three algorithms, MD2, MD4, and MD5, according to the specification version, and the message digest generated by the MD algorithm is 128 bits. In terms of security, the security of the three algorithms is ranked as MD5> MD4> MD2, and therefore, in order to improve security, in the present embodiment, the MD algorithm is preferably the MD5 algorithm, and when the first message digest is calculated by the MD5 algorithm, the first message digest may also be referred to as MD5 value or 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 by using a SHA algorithm.
Specifically, the SHA (Secure Hash Algorithm) Algorithm is also a message digest Algorithm, and the SHA family has five algorithms, SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512, respectively, where SHA-224, SHA-256, SHA-384, and SHA-512 are collectively referred to as SHA-2. The number of bits of the message digests generated by different SHA algorithms is different, such as 160 bits for the message digest generated by SHA-1 algorithm and 224 bits for the message digest generated by SHA-224 algorithm. In this embodiment, a specific SHA algorithm may be selected according to actual situations, for example, the SHA algorithm is SHA-256.
The determining module 403 is configured to determine whether a second message digest matching the first message digest is stored in a preset database.
Specifically, the preset database is a database for storing pictures, and the type of the database may be selected according to actual situations, for example, the database is a Mongo database, a Redis database, a Memcache database, or the like. It is intended to provide an extensible 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 the same as the first message digest, for example, the first message digest is abf, and if the second message digest stored in the database is also abf, it indicates that the second message digest matching the first message digest exists in the database.
In one embodiment, the database is a mongo database, and a data storage structure of the mongo database comprises a picture ID field, a picture data field and a message digest field. The image ID field is an identifier for uniquely identifying one image, the data of the ID fields corresponding to different images are different, and the image can be conveniently inquired through the data of the ID field; the data corresponding to the picture data field is picture data; the data corresponding to the message digest field is a number obtained by performing message digest generation on the picture data. In other embodiments of the present invention, the data storage structure of the logo database further includes a picture suffix field, and the data corresponding to the field is used to distinguish the format of the 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 data corresponding to the message digest field in the monogo database; and the message digest judging module is used for 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 includes the message digest field, the message digest of each picture stored in the database can be found by searching the data corresponding to the message digest field in the database. Comparing the message digest of each searched picture with the first message digest, and if the currently 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, continuing to compare the searched message digests of other pictures with the first message digest until the same message digest as the first message digest is searched or the message digests of all the pictures are completely compared, ending the search and comparison of the message digests and obtaining a judgment result.
A storage module 404, configured to store the picture to be stored in the database and return a storage address of the picture to be stored to the terminal device if the second message digest is not stored in the database.
Specifically, when the second message digest is not stored in the database, it indicates that there is no picture in the database that is the same as the picture to be stored, 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 Uniform Resource Locator (URL), and in an embodiment, the storage address includes a picture ID of the picture to be stored, so that the picture to be stored can be found quickly through the picture ID.
The storage module 404 is further configured to, if the second message digest is stored in the database, return 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 storing the picture again, the storage module 404 may discard the data of the picture to be stored, so as to save the 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 further return 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.
According to the embodiment of the invention, the picture to be stored uploaded by the terminal equipment through the first application program interface is received; calculating a first message abstract 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; 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; and if the second message abstract is stored in the database, returning the storage address of the picture associated with the second message abstract 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 can be determined according to the information abstract, and the picture is stored only when the picture does not exist in the database, so that the same picture can not be stored repeatedly, and the storage space is saved.
Further, in an exemplary embodiment, the picture storage apparatus 400 further includes: and (5) a query module.
The receiving module 401 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 of the picture to be queried includes a picture ID.
Specifically, the server provides a second Application Programming Interface (API) to the outside for the terminal device to query the picture from the server through the second API, that is, the first and second API is an interface for querying the picture. The terminal device is provided with a corresponding application client or a corresponding webpage client, and a user can send the picture query instruction to the server through the application client or the webpage client in the terminal device. When the picture needs to be queried from the server, the terminal device 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 device. 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 resource 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 this embodiment and the first application program interface in the above embodiment are preferably written in the golang language, but of course, in other embodiments of the present invention, the second application program interface may also be written in other languages, for example, in the C language, the C + + language, and the like.
In the embodiment of the invention, the first application program interface and the second application program interface are written by the golang language, so that the server in the embodiment of the invention can be deployed on a single machine, and the invention has the advantages of rapid 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 logo storage structure for storing picture data in the logo database includes the 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 returning 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 returning module 405 further adds Content-Type field data and Accept-Range field data to the picture data, where the field data is used to tell the terminal device the Content Type of the picture Content actually returned, and the Accept-Range field data is used to indicate whether the server supports the breakpoint request, and if so, after the network of the terminal device is interrupted, the remaining data can be continuously acquired after the network is restored, and the data acquisition is never 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 efficiency of inquiring the picture can be improved.
Fig. 5 is a schematic diagram of a hardware architecture of the server 5 according to the present invention. In the present embodiment, the server 5 is a device capable of automatically performing numerical calculation and/or information processing in accordance with a command set or stored in advance. For example, a rack server, a blade server, a tower server or a rack server (including an independent server or a server cluster composed of a plurality of 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 via a system bus. Wherein:
the memory 501 includes at least one type of computer-readable storage medium including a flash memory, a hard disk, a multimedia card, a card-type 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 storage 501 may be an internal storage module of the server 5, such as a hard disk or a 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 provided on the server 5, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like. Of course, the memory 501 may also include both an internal storage module of the server 5 and an external storage device thereof. In this embodiment, the memory 501 is generally used for storing an operating system and various types of application software installed in the server 5, such as program codes of a picture storage method. Further, the memory 501 may also be used to temporarily store various types of data that have been output or are to be output.
Processor 502 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data Processing chip in some embodiments. The processor 502 is generally used for controlling the overall operation of the server 5, such as performing control and processing related to data interaction or communication with the server 5. In this embodiment, the processor 502 is configured to execute program codes stored in the memory 501 or process data.
The network interface 503 may comprise a wireless network interface or a wired network interface, and the network interface 503 is typically used to establish communication links between the server 5 and other servers. For example, the network interface 503 is used to connect the server 5 with an external terminal via 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 of mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), a 4G network, a 5G network, Bluetooth (Bluetooth), or Wi-Fi.
It is noted that FIG. 5 only shows servers having components 501-503, but it is understood that not all of the shown components are required and that more or fewer components may be implemented instead.
In this embodiment, the picture storing method stored in the memory 501 may be further divided into one or more program modules and executed by one or more processors (in this embodiment, the processor 502) to complete the present invention.
The embodiment of the application provides a computer-readable storage medium, on which a computer program is stored, and the computer program, when executed by a processor, implements the steps of the picture storage method in the embodiment. In this embodiment, the computer-readable storage medium includes a flash memory, a hard disk, a multimedia card, a card type 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 the 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 the server, such as a plug-in hard disk provided on the server, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like. Of course, the computer-readable storage medium may also include both an internal storage unit of the server and an external storage device thereof. In this embodiment, the computer-readable storage medium is generally used for storing an operating system and various types of application software installed in the server, for example, the program codes of the image storage method in the embodiment, and the like. Further, 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 by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of multiple computing devices, and alternatively, they may be implemented by program code executable by a computing device, such that they may be stored in a storage device and executed by a computing device, and in some cases, the steps shown or described may be performed in an order different than that described herein, or they may be separately fabricated into individual integrated circuit modules, or multiple ones of 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.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a general hardware platform, and certainly can also be implemented by hardware. It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware related to instructions of a computer program, which can be stored in a computer readable storage medium, and when executed, can include the processes of 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 (RAM), or the like.
Finally, it should be noted that: the above embodiments are only used for illustrating the technical solutions 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 solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present application.
Claims (10)
1. A picture storage method, comprising:
receiving a picture to be stored uploaded by a terminal device through a first application program interface;
calculating a first message abstract 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;
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;
and if the second message abstract is stored in the database, returning the storage address of the picture associated with the second message abstract to the terminal equipment.
2. The method according to claim 1, wherein the step of calculating the first message digest of the picture to be stored through the first application program interface comprises:
and calculating the first message abstract 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 method according to claim 1, wherein the step of calculating the first message digest of the picture to be stored through the first application program interface comprises:
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 method according to any one of claims 1 to 4, wherein the database is a logo database, a data storage structure of the logo 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 matching 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.
6. The picture storage method according to claim 5, further comprising:
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;
and when the picture to be inquired is inquired, returning the picture data corresponding to the picture to be inquired to the terminal equipment so that the terminal equipment displays the picture to be inquired according to the picture data.
7. A picture storage device comprising:
the receiving module is used for receiving the picture to be stored uploaded by the terminal equipment through the first application program interface;
the calculation module is used for calculating a first message abstract of the picture to be stored through the first application program interface;
the judging module is used for judging whether a second message abstract matched with the first message abstract is stored in a preset database;
the storage module is used for 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 abstract is not stored in the database;
and the return module is used for returning the storage address of the picture associated with the second message abstract to the terminal equipment if the second message abstract is stored in the database.
8. The image storage device according to claim 7, wherein the database is a mongo database, a data storage structure of the mongo database includes an image ID field, an image data field, and a message digest field, and the determining module is further configured to search for data corresponding to the message digest field in the mongo database; and the message digest judging module is used for judging whether a second message digest matched with the first message digest exists in the data corresponding to the message digest field.
9. A server, characterized by 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 storing method according to any one of claims 1 to 6 when executing the computer program.
10. A computer-readable storage medium having stored thereon a computer program, characterized in that: the computer program, when executed by a processor, implements the steps of the picture storage method of any one of claims 1 to 6.
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 true CN111291207A (en) | 2020-06-16 |
CN111291207B 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) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113656618A (en) * | 2021-08-12 | 2021-11-16 | 工银科技有限公司 | Picture synchronization method and device, electronic equipment and readable storage medium |
Citations (5)
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 |
-
2020
- 2020-01-22 CN CN202010074907.8A patent/CN111291207B/en active Active
Patent Citations (5)
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)
Title |
---|
朱晓辉;王杰华;石振国;陈苏蓉;: "海量图片的分布式存储及负载均衡研究" * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113656618A (en) * | 2021-08-12 | 2021-11-16 | 工银科技有限公司 | Picture synchronization method and device, electronic equipment and readable storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN111291207B (en) | 2024-02-06 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110737658B (en) | Data fragment storage method, device, terminal and readable storage medium | |
US10225145B2 (en) | Method and device for updating client | |
CN111756674B (en) | Network communication method, system, device and computer readable storage medium | |
CN109391673B (en) | Method, system and terminal equipment for managing update file | |
CN107682426B (en) | Interface proxy method and application server | |
CN108491715B (en) | Terminal fingerprint database generation method and device and server | |
CN113132267B (en) | Distributed system, data aggregation method and computer readable storage medium | |
CN112486915B (en) | Data storage method and device | |
CN111580948A (en) | Task scheduling method and device and computer equipment | |
CN115543429A (en) | Project environment building method, electronic equipment and computer readable storage medium | |
CN113656098B (en) | Configuration acquisition method and system | |
CN109951551B (en) | Container mirror image management system and method | |
CN111291207B (en) | Picture storage method, device and server | |
CN113535206B (en) | Multi-version code upgrading method and system | |
CN111176706A (en) | Terminal upgrading method and device, electronic equipment and storage medium | |
CN106446138B (en) | Data packet storage method and device | |
CN112969198A (en) | Data transmission method, terminal and storage medium | |
CN105610596B (en) | Resource directory management method and network terminal | |
CN101170576A (en) | A method, system and device for file upload | |
CN107908634B (en) | Cache control method of browser and mobile terminal | |
CN113162997B (en) | Data transmission method and device, electronic equipment and readable storage medium | |
CN114466004A (en) | File transmission method, system, electronic equipment and storage medium | |
CN114928610A (en) | Data update notification method, data processing method, device, equipment and medium | |
CN110377665B (en) | Data synchronization method and device, electronic equipment and storage medium | |
CN113032019A (en) | Multi-factor-based android device identification method and device and storage medium |
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 |
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. |
|
CB02 | Change of applicant information | ||
GR01 | Patent grant | ||
GR01 | Patent grant |