File reading method and device, storage medium and electronic device
By generating tokens related to the storage path and random numbers for security verification and gradually sending the file content, the problem of low file reading security is solved and higher security and reliability are achieved.
Patent Information
- Application Number
- CN202310645518.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-01
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2043-06-01
AI Technical Summary
The security of file reading in the existing technology is low, and the file storage path may be traversed and generated, resulting in a high risk of file leakage.
By generating a token that has a mapping relationship with the storage path and random number, combined with the file length and storage path information, the file content is sent step by step after security verification.
Improves the security of file reading, avoids reading files directly through the storage path, and ensures the security and integrity of information transmission.
Smart Images

Figure CN116578541B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of financial technology, and specifically, to a file reading method and device, a storage medium, and an electronic device. Background Art
[0002] In related technologies, files are often stored in a memory, server, database, etc. When it is necessary to read a file stored in the memory, server, database, etc., the file is often read through the storage path of the file in the memory, server, or database. This method has the disadvantage of low security in file reading. For example, the storage path of the file in the memory may be traversed and generated, that is, the storage path files of all possible files may be randomly generated, and there is a risk of file leakage, resulting in low security in file reading.
[0003] Currently, no effective solution has been proposed to the problem of low security in file reading in related technologies. Summary of the Invention
[0004] The main purpose of this application is to provide a file reading method and device, a storage medium and an electronic device to solve the problem of low security of file reading in related technologies.
[0005] To achieve the above-mentioned purpose, according to one aspect of the present application, a file reading method is provided. The method comprises: when a target file on a first storage path is selected as a file to be uploaded, generating a first token according to the first storage path, target information included in the target file, and a generated random number, wherein the first token has a mapping relationship with the random number and the first storage path, and the first token is stored in a target token set; forming first return information by combining the first token, the first storage path, and the first file length of the target file, and sending the first return information to a browser; obtaining a first file reading request sent by the browser; when a second token is obtained in the first file reading request, searching for a token identical to the second token in the target token set; when the first token identical to the second token is found, sending at least part of the target information to the browser.
[0006] Optionally, when a second token is obtained in the first file reading request, searching for a token identical to the second token in the target token set includes: when the first file reading request carries second return information, a first starting position and a second file length, and the second return information includes a second token, obtaining the second token included in the second return information, wherein the second file length is less than or equal to the first file length; and searching for a token identical to the second token in the target token set.
[0007] Optionally, when the first token identical to the second token is found, sending at least part of the target information to the browser includes: when the first token identical to the second token is found and the second return information also includes a second storage path, obtaining the second storage path included in the second return information, reading the information of the second file length starting from the first starting position in the file on the second storage path, and obtaining the first information to be sent, wherein, when the first storage path and the second storage path are the same, the first information to be sent is at least part of the target information; and sending the first information to be sent to the browser.
[0008] Optionally, the method further includes: when the first information to be sent is the first part of the target information, obtaining a second file reading request sent by the browser; when the second file reading request carries third return information, a second starting position and a third file length, and the third return information includes the second token, obtaining the second token included in the third return information, wherein the third file length is less than the first file length, and the sum of the second file length and the third file length is less than or equal to the first file length; searching for a token identical to the second token in the target token set; when the first token identical to the second token is found and the third return information also includes the second storage path, obtaining the second storage path included in the third return information, reading the information of the third file length starting from the second starting position in the file on the second storage path, and obtaining the second information to be sent, wherein, when the first storage path and the second storage path are the same, the second information to be sent is the second part of the information in the target information that is different from the first part of the information, and the target information includes the first part of the information and the second part of the information; and sending the second information to be sent to the browser.
[0009] Optionally, the method further includes: in a case where the first information to be sent is the first part of the target information, obtaining a second file reading request sent by the browser; in a case where the second file reading request carries third return information and a third file length, and the third return information includes the second token, obtaining the second token included in the third return information, wherein the third file length is less than the first file length, and the sum of the second file length and the third file length is less than or equal to the first file length; searching for a token identical to the second token in the target token set; and when the first token identical to the second token is found, and the third return information also includes the second stored token. In the case of a different storage path, obtaining the second storage path included in the third return information; determining a second starting position according to the pre-stored first starting position and the second file length, wherein the second starting position is the next position of the first information to be sent in the file on the second storage path; reading information of the third file length starting from the second starting position in the file on the second storage path to obtain second information to be sent, wherein, in the case that the first storage path and the second storage path are the same, the second information to be sent is the second part of information in the target information, and the target information includes the first part of information and the second part of information; and sending the second information to be sent to the browser.
[0010] Optionally, sending the first information to be sent to the browser includes: when the second return information also includes a second storage path, obtaining the information included in the file on the second storage path; obtaining the random number and the first storage path that have the mapping relationship with the first token; generating a third token based on the first storage path, the information included in the file on the second storage path, and the random number, wherein the third token is generated in the same manner as the first token; and when the first token and the third token are the same, sending the first information to be sent to the browser.
[0011] Optionally, the information of the length of the second file is read from the first starting position in the file on the second storage path to obtain the first information to be sent, including: when the second return information also includes the second storage path, obtaining the information included in the file on the second storage path; obtaining the random number and the first storage path that have the mapping relationship with the first token; generating a third token based on the first storage path, the information included in the file on the second storage path and the random number, wherein the generation method of the third token is the same as the generation method of the first token; when the first token and the third token are the same, reading the information of the length of the second file from the first starting position in the file on the second storage path to obtain the first information to be sent.
[0012] Optionally, the first starting position is used to indicate the position of the first byte to be read, and the second file length is used to indicate the length of bytes to be read starting from the first starting position.
[0013] To achieve the above-mentioned purpose, according to another aspect of the present application, a file reading device is provided. The device comprises: a generating module for generating a first token according to the first storage path, target information included in the target file, and a generated random number when a target file on a first storage path is selected as a file to be uploaded, wherein the first token has a mapping relationship with the random number and the first storage path, and the first token is stored in a target token set; a first processing module for forming first return information from the first token, the first storage path, and the first file length of the target file, and sending the first return information to a browser; a first acquiring module for acquiring a first file reading request sent by the browser; a first searching module for searching for a token identical to the second token in the target token set when a second token is acquired in the first file reading request; and a first sending module for sending at least part of the target information to the browser when the first token identical to the second token is found.
[0014] Through the present application, the following steps are adopted: when the target file on the first storage path is selected as the file to be uploaded, a first token is generated according to the first storage path, the target information included in the target file and the generated random number, wherein the first token has a mapping relationship with the random number and the first storage path, and the first token is stored in the target token set; the first token, the first storage path and the first file length of the target file are combined into a first return information, and the first return information is sent to the browser; a first file read request sent by the browser is obtained; when a second token is obtained in the first file read request, a token identical to the second token is searched in the target token set; when a first token identical to the second token is found, the target information is sent to the browser At least part of the information in the file, that is, when the first file reading request sent by the browser is obtained, it can be indicated that the file on the storage path is desired to be read. In this case, the token carried in the first file reading request can be found from the token set. When a token identical to the token carried in the first file reading request is found, it can be indicated that the current situation is sufficiently secure. In this case, at least part of the information in the file is allowed to be sent to the browser. By determining whether the tokens are the same, the information in the file is sent to the browser while ensuring the security of the sending process, thereby avoiding reading the information in the file directly through the storage path of the file, solving the problem of low security of file reading in related technologies, and thus achieving the effect of improving the security of file reading. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The accompanying drawings, which constitute part of this application, are intended to provide a further understanding of this application. The exemplary embodiments and descriptions of this application are intended to explain this application and do not constitute an improper limitation on this application. In the accompanying drawings:
[0016] Figure 1 This is a schematic diagram of an application scenario of a file reading method according to an embodiment of the present application;
[0017] Figure 2 is a flowchart of a file reading method provided according to an embodiment of the present application;
[0018] Figure 3 is a schematic diagram of an optional second return message according to an embodiment of the present application;
[0019] Figure 4 is a schematic diagram of an optional method of searching for a second token in a target token set according to an embodiment of the present application;
[0020] Figure 5 is a schematic diagram of information in a file according to an embodiment of the present application;
[0021] Figure 6is a schematic diagram of an optional file reading method according to an embodiment of the present application;
[0022] Figure 7 is a schematic diagram of a file reading device provided according to an embodiment of the present application;
[0023] Figure 8 This is a schematic diagram of an electronic device provided according to an embodiment of the present application. DETAILED DESCRIPTION
[0024] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in this application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0025] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.
[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0027] In order to better understand the application scenarios of the file reading method in the embodiment of the present application, the application scenarios of the file reading method in the embodiment of the present application are explained and illustrated in combination with optional embodiments below, which can be applied to but not limited to the embodiment of the present application.
[0028] The file reading method in the embodiment of the present application can be applied to, but is not limited to, determining whether to allow reading of information in a file when it is desired to read a file from a storage space such as a database, a memory, or a file system. In this embodiment, it can be applied to, but is not limited to, reading a file to be uploaded from a file stored in the operating system where the terminal 102 is located as an example. Figure 1 is a schematic diagram of an application scenario of a file reading method according to an embodiment of the present application, such as Figure 1As shown, a browser 102-1 and a local file server 102-2 are deployed on the terminal 102. The local file server 102-2 is a server deployed on the operating system of the terminal 102. The operating system of the terminal 102 includes one or more storage paths, each of which stores a corresponding file. When a user wishes to upload a target file on a first storage path in the operating system of the terminal 102 to the terminal server 104, the local file server 102-2 may determine, but is not limited to, whether to allow at least part of the message in the target file to be sent to the browser 102-1. The specific steps are as follows:
[0029] In step S101, the user clicks the upload button displayed on the file upload interface of the browser 102-1.
[0030] In step S102, a request is sent to the local file server 102-2 via the browser 102-1. The local file server 102-2 displays a selection interface for files to be uploaded. The user selects the target file on the first storage path displayed in the interface as the file to be uploaded.
[0031] In step S103, the local file server 102-2 generates a first token based on the first storage path, the target information included in the target file, and the generated random number; combines the first token, the first storage path, and the first file length of the target file into first return information, and sends the first return information to the browser.
[0032] In step S104, the browser 102-1 initiates a first file reading request to the local file server 102-2, where the file reading request carries second return information.
[0033] In step S105 , when the local file server 102 - 2 finds the first token that is identical to the second token, the local file server 102 - 2 sends the target information to the browser 102 - 1 .
[0034] In step S106 , the browser 102 - 1 uploads the target information to the terminal server 104 .
[0035] It should be noted that, in this embodiment, the local file server 102-2 and the terminal server 104 are different servers. The local file server 102-2 can be used, but is not limited to, to determine whether to allow reading of information in files stored in the operating system of the terminal 102, and the terminal server 104 can be used, but is not limited to, to receive files uploaded by the browser 102-1.
[0036] The present invention will be described below in conjunction with preferred implementation steps. Figure 2 is a flowchart of a file reading method provided in an embodiment of the present application, such as Figure 2 As shown, the method includes the following steps:
[0037] Step S201: When a target file on a first storage path is selected as a file to be uploaded, a first token is generated according to the first storage path, target information included in the target file, and a generated random number, wherein the first token has a mapping relationship with the random number and the first storage path, and the first token is stored in a target token set;
[0038] Step S202: compose first return information from the first token, the first storage path, and the first file length of the target file, and send the first return information to the browser;
[0039] Step S203, obtaining a first file reading request sent by the browser;
[0040] Step S204: when a second token is obtained in the first file read request, searching for a token identical to the second token in the target token set;
[0041] Step S205: When the first token identical to the second token is found, at least part of the target information is sent to the browser.
[0042] In the technical solution provided in step S201 above, the target information may include, but is not limited to, the file content of the target file. Each file in the storage path may have, but is not limited to, a one-to-one correspondence with a random number, with each file corresponding to a different random number. Optionally, the random number may be, but is not limited to, a 32-bit random number or a 16-bit random number generated using a computer language such as Java or C, and this application does not impose any restrictions on this.
[0043] Optionally, in the file reading method provided in the embodiment of the present application, the first storage path may include, but is not limited to, a storage path of a file in a storage space used to store files on a server, a memory, a database, etc., and may, but is not limited to, generate a first token based on the first storage path, the target information included in the target file, and the random number of the target file through a hash algorithm (such as: SM3 algorithm, SHA256 algorithm, SHA384 algorithm or SHA512 algorithm, etc.), and store the first token in the target token set.
[0044] Optionally, in the file reading method provided in the embodiment of the present application, the first token can be generated in the following manner, but is not limited to: generating a random number for the target file, concatenating the first storage path, target information and random number to obtain token parameters; calculating the algorithm value of the hash algorithm under the token parameters to obtain the first token.
[0045] In detail, the first storage path and target information can be, but is not limited to, encoded and decoded into hexadecimal (or decimal, binary, etc.) characters, and then the encoded and decoded first storage path and target information are concatenated with a random number to obtain a token parameter.
[0046] For example: the first storage path is "C:\A.txt", the target information is "1122334455667788", and the random number is "B7DA5C48AC5856E767354144E5D9EC547D7FB25CE22C744EBABEE477CF58FEB C", in this case, you can, but are not limited to, convert "C:\A.txt" into hexadecimal characters by ACSII encoding and decoding to obtain 433A5C412E747874, convert "112233445667788" into hexadecimal characters by ACSII encoding and decoding to obtain 31313232333334343535363637373838, and then concatenate them to calculate token = SHA256("C:\A.txt"+"112233445667788"+"B7DA5C48AC5856E767354144E5D9EC547D7F B25CE22C744EBABEE477CF58FEBC")=SHA256(433A5C412E74787431313232333334343535363637373838B7DA5C48AC5856E767354144E5D9EC547D7FB25CE22C744EBABEE477CF58FEBC")=7E507D2987CF53F237DCBF696824A89AA7E6D23B83844D469B458E8ED22F358A, that is, the first token is:
[0047] "7E507D2987CF53F237DCBF696824A89AA7E6D23B83844D469B458E8ED22F358A". It should be noted that "+" indicates splicing.
[0048] In the technical solution provided in the above step S202, the first token, the first storage path and the first file length of the target file can be spliced together according to the target format, but is not limited to, to obtain the first return information. The target format can be, but is not limited to, the format of the return information that allows communication between the browser and the local file server. In this way, communication between the browser and the local file server is achieved.
[0049] Optionally, in the file reading method provided in the embodiment of the present application, the first file length of the target file may include but is not limited to the number of bytes of the target file, the number of bits occupied by the target file, etc., and may include but is not limited to sending the first return information to the browser, and the browser may include but is not limited to storing the first return information. In this way, only the browser that has cached the first return information can initiate the first file reading request, ensuring that the browser that initiates the first file reading request is a trusted browser, thereby improving the security of the browser sending the first file reading request.
[0050] In the technical solution provided in the above step S203, there may be a certain time interval between the time when the first file request is obtained and the time when the first return information is sent to the browser, and the token has an effective period. The browser can, but is not limited to, send the first file reading request within the effective period of the token. If the effective period of the token is exceeded, the browser can, but is not limited to, re-execute the above steps S101 and S102 to regenerate the token. In this way, the security of obtaining the first file reading request is improved.
[0051] In the technical solution provided in the above step S204, when the first file read request sent by the browser is obtained, it can be indicated that the target file is desired to be read. In such a case, the second token can be obtained from the first file read request, but it is not limited to the second token. However, the first file read request may not carry any token, that is, the second token cannot be obtained from the first file read request. In such a case, it can be indicated that the first file read request is an abnormal request, that is, the first file read request is an unsafe request. In such a case, the first file read request can be terminated, but it is not limited to prohibiting the reading of the file. In this way, the interception of unsafe requests is achieved, and the security of reading files is improved.
[0052] Optionally, in the file reading method provided in the embodiment of the present application, when the first file reading request sent by the browser is obtained, it can be indicated that the target file is desired to be read. In such a case, the second token can be obtained from the first file reading request, but is not limited to. When the second token is obtained from the first file reading request, the second token may be a correct token or an incorrect token, that is, the token carried in the first file reading request is not the token required to read at least part of the information in the target file. In such a case, a token identical to the second token can be searched from the target token set, but is not limited to being searched, thereby verifying the correctness of the second token and improving the correctness of the second token.
[0053] In an exemplary embodiment, a token identical to a second token can be searched for in a target token set in the following manner, but is not limited to: when the first file read request carries second return information, a first starting position, and a second file length, and the second return information includes a second token, the second token included in the second return information is obtained, wherein the second file length is less than or equal to the first file length; and a token identical to the second token is searched for in the target token set.
[0054] Optionally, in the file reading method provided in the embodiment of the present application, the second return message may be, but is not limited to, composed in the same manner as the first return message. Figure 3 is a schematic diagram of an optional second return message according to an embodiment of the present application, such as Figure 3 As shown, the first file read request carries the second return information, the first starting position and the second file length, wherein the second return information may include but is not limited to the second token "7E507D2987CF53F237DCBF696824A89AA7E6D23B83844D469B458E8ED22F358A", the first starting position may be but is not limited to "0", and the second file length may be but is not limited to "6". In this case, it is possible but not limited to obtain the second token "7E507D2987CF53F237DCBF696824A89AA7E6D23B83844D469B458E8ED22F358A" from the second return message, and then search for the token identical to the second token in the target token set.
[0055] In an exemplary embodiment, at least part of the target information can be sent to the browser in the following manner, but is not limited to: when the first token that is identical to the second token is found and the second return information also includes a second storage path, the second storage path included in the second return information is obtained, and the information of the second file length is read from the first starting position in the file on the second storage path to obtain the first information to be sent, wherein, when the first storage path and the second storage path are the same, the first information to be sent is at least part of the target information; and the first information to be sent is sent to the browser.
[0056] Optionally, in the file reading method provided in the embodiment of the present application, the target token set may include but is not limited to recording one or more tokens. In this case, it is possible but not limited to searching the target token set for a first token that is identical to a second token. Figure 4 is a schematic diagram of an optional method of searching for a second token in a target token set according to an embodiment of the present application, such as Figure 4 As shown, the first token identical to the second token "7E507D2987CF53F237DCBF696824A89AA7E6D23B83844D469B458E8ED22F358A" can be found from the target token set, but is not limited to. Optionally, the token A1 having a mapping relationship and the random number A2 and the storage path A3 can be recorded in the target token set, but is not limited to, for example: the random number "B7DA5C48AC5856E767354144E5D9EC547D7FB25CE22C744EBABEE477CF58FEB C" corresponding to the first token and the first storage path "C:\A.txt" are recorded in the target token set, or only the first token is recorded in the target token set. This application does not impose any restrictions on this.
[0057] Optionally, in the file reading method provided in an embodiment of the present application, when the first token that is identical to the second token is found, and the second return information may also include but is not limited to including a second storage path, the second storage path may be the same as the first storage path. In this case, the information of the second file length read from the first starting position in the file on the second storage path is at least part of the information in the file on the first storage path.
[0058] Optionally, in the file reading method provided in the embodiment of the present application, the file on the second storage path may be large, for example: the data volume or number of bytes of the file is large, which has exceeded the data volume or number of bytes of the file that the browser can process at one time. In such a case, the information in the file on the second storage path can be read in batches, but is not limited to. It is possible, but not limited to, to read part of the information in the file on the first storage path of the second file length from the first starting position when the number of bytes of the file on the second storage path is greater than the byte count threshold, that is, the second file length is a file length that meets the processing capability of the browser. In this way, browser overload is avoided and the efficiency of the browser in uploading information in files is improved.
[0059] Optionally, in the file reading method provided in the embodiment of the present application, the file on the second storage path may be smaller, for example: the data volume or number of bytes of the file is smaller, and the browser can complete the processing in one time; it is possible but not limited to the case where the number of bytes of the file on the second storage path is less than or equal to the byte number threshold, to read all the information in the file on the second storage path, that is, the first starting position is the starting position of the information in the file on the second storage path, and the second file length is the total file length in the file on the second storage path. In this way, the processing capability of the browser is fully utilized and the utilization rate of the browser's processing resources is improved.
[0060] In an exemplary embodiment, the method further includes: when the first information to be sent is the first portion of information in the target information, obtaining a second file read request sent by the browser; when the second file read request carries third return information, a second starting position, and a third file length, and the third return information includes the second token, obtaining the second token included in the third return information, wherein the third file length is less than the first file length, and the sum of the second file length and the third file length is less than or equal to the first file length; searching for a token identical to the second token in the target token set; when the first token identical to the second token is found, and the third return information also includes the second storage path, obtaining the second storage path included in the third return information, reading information of the third file length starting from the second starting position in the file on the second storage path, and obtaining second information to be sent, wherein, when the first storage path and the second storage path are the same, the second information to be sent is the second portion of information in the target information that is different from the first portion of information, and the target information includes the first portion of information and the second portion of information; and sending the second information to be sent to the browser.
[0061] Optionally, in the file reading method provided in the embodiment of the present application, the second file reading request sent by the browser may be, but is not limited to, still desiring to read the second part of the target information. In this case, it can indicate that the browser continuously reads the information in the target information. In this case, it may be, but is not limited to, still carrying the second token in the second file reading request. When a token identical to the second token is found from the target token set, the second file reading request may be, but is not limited to, carrying the second starting position. In this case, it may be, but is not limited to, reading information of the third file length from the second starting position in the file on the second storage path to obtain the second information to be sent. In this way, the need to repeatedly generate tokens for the same file when continuously reading different information in the same file is avoided, thereby saving computer resources and improving the utilization of computer resources.
[0062] Optionally, in the file reading method provided in an embodiment of the present application, the second information to be sent is the second part of information in the target information that is different from the first part of information, that is, the second information to be sent is part of the information that does not overlap with the first part of information. In this way, repeated information in the reading file is avoided and the efficiency of reading information in the file is improved.
[0063] In an exemplary embodiment, the above method also includes: in a case where the first information to be sent is the first part of the target information, obtaining a second file reading request sent by the browser; in a case where the second file reading request carries third return information and a third file length, and the third return information includes the second token, obtaining the second token included in the third return information, wherein the third file length is less than the first file length, and the sum of the second file length and the third file length is less than or equal to the first file length; searching for a token identical to the second token in the target token set; and when the first token identical to the second token is found, and the third return information also includes the In the case of the second storage path, the second storage path included in the third return information is obtained; the second starting position is determined according to the pre-stored first starting position and the second file length, wherein the second starting position is the next position of the first information to be sent in the file on the second storage path; the information of the third file length is read from the second starting position in the file on the second storage path to obtain the second information to be sent, wherein, in the case that the first storage path and the second storage path are the same, the second information to be sent is the second part of the target information, and the target information includes the first part of the information and the second part of the information; and the second information to be sent is sent to the browser.
[0064] Optionally, in the file reading method provided in an embodiment of the present application, the second file reading request sent by the browser may, but is not limited to, still be intended to read the second portion of information in the target information. In this case, it can indicate that the browser is continuously reading information in the target information. In this case, the second file reading request may, but is not limited to, carry third return information and a third file length, but not carry a second starting position. The second starting position may, but is not limited to, be determined based on the pre-stored first starting position and second file length. In this way, the content carried in the second file reading request is reduced, and the sending rate of the second file reading request is improved.
[0065] Optionally, in the file reading method provided in an embodiment of the present application, the second starting position can be determined in the following manner, but is not limited to: obtaining a pre-stored first starting position and a second file length, and determining the sum of the pre-stored first starting position and the second file length as the second starting position.
[0066] In an exemplary embodiment, the first information to be sent can be sent to the browser in the following manner, but is not limited to: when the second return information also includes a second storage path, obtaining the information included in the file on the second storage path; obtaining the random number and the first storage path that have the mapping relationship with the first token; generating a third token based on the first storage path, the information included in the file on the second storage path, and the random number, wherein the generation method of the third token is the same as the generation method of the first token; when the first token and the third token are the same, sending the first information to be sent to the browser.
[0067] Optionally, in the file reading method provided in the embodiment of the present application, the second storage path may be the same as the first storage path. When the second storage path is the same as the first storage path, the third token may be, but is not limited to being, the same as the first token. In this case, it can be indicated that the second storage path is correct, that is, the second storage path is secure. In this case, the first information to be sent can be, but is not limited to, sent to the browser. In this way, the security of the second storage path is verified.
[0068] Optionally, in the file reading method provided in the embodiment of the present application, the second storage path may be different from the first storage path. In such a case, the third token may be, but is not limited to being, different from the first token. In such a case, it can be indicated that the second storage path is wrong, that is, the second storage path is unsafe. In such a case, it can be, but is not limited to, prohibited from sending the first information to be sent to the browser. In this way, information can be sent to the browser only when the tokens are the same, thereby improving the security of information sending.
[0069] Optionally, in the file reading method provided in the embodiment of the present application, the generation method of the third token can be but is not limited to the same as the generation method of the first token. For example, the third token and the first token can be but are not limited to both being generated by a hash algorithm. Generating the third token and the first token by the same generation method improves the comparability between the tokens.
[0070] In an exemplary embodiment, the first information to be sent can be obtained in the following manner, but is not limited to: when the second return information also includes a second storage path, obtaining the information included in the file on the second storage path; obtaining the random number and the first storage path that have the mapping relationship with the first token; generating a third token based on the first storage path, the information included in the file on the second storage path, and the random number, wherein the generation method of the third token is the same as the generation method of the first token; when the first token and the third token are the same, reading the information of the second file length starting from the first starting position in the file on the second storage path to obtain the first information to be sent.
[0071] Optionally, in the file reading method provided in the embodiment of the present application, it is possible, but not limited to, to obtain the information included in the file on the second storage path when the first token that is identical to the second token is found and the second return information also includes the second storage path. When the third token is identical to the first token, it is possible, but not limited to, to read the information of the second file length from the first starting position in the file on the second storage path to obtain the first information to be sent. In this way, it is achieved by first determining whether the first token is identical to the second token to determine whether the file information on the storage path is allowed to be obtained, and then determining whether the second token is identical to the third token to determine whether the information in the file is allowed to be read. This provides multi-layer protection for the files on the storage path and improves the security of file reading.
[0072] Optionally, in the file reading method provided in the embodiment of the present application, the second storage path may be the same as the first storage path. When the second storage path is the same as the first storage path, the third token may be, but is not limited to being, the same as the first token. In such a case, it can be indicated that the second storage path is correct, that is, the second storage path is safe. In such a case, it is possible but not limited to reading the information of the second file length from the first starting position in the file on the second storage path to obtain the first information to be sent, thereby improving the security of the information in the read file.
[0073] Optionally, in the file reading method provided in the embodiment of the present application, the second storage path may be different from the first storage path. In such a case, the third token may be, but is not limited to being, different from the first token. In such a case, it can be indicated that the second storage path is wrong, that is, the second storage path is unsafe. In such a case, it may be, but is not limited to, prohibiting the reading of information in the file on the second storage path. In this way, the information in the file on the storage path can only be read when the tokens are the same, thereby avoiding the leakage of information in the file.
[0074] In an exemplary embodiment, the first starting position is used to indicate the position of the first byte to be read, and the second file length is used to indicate the length of bytes to be read starting from the first starting position.
[0075] Optionally, in the file reading method provided in the embodiment of the present application, the information in the file on the second storage path may include, but is not limited to, multiple bytes, and each byte may have, but is not limited to, a position in the target file. Figure 5 is a schematic diagram of information in a file according to an embodiment of the present application, such as Figure 5 As shown, in such a case, it is possible but not limited to start from the first starting position and read the bytes of the second file length. In this way, it is achieved that part of the information in the file on the storage path is read, and the flexibility of reading the information in the file is improved.
[0076] Optionally, in the file reading method provided in an embodiment of the present application, the first starting position is used to indicate the position of the first bit to be read, and the second file length is used to indicate the length of the bits read starting from the first starting position.
[0077] In the technical solution provided in step S205 above, if a first token identical to a second token is found, it can be indicated that the first file read request is safe. In this case, at least a portion of the target information can be sent to the browser, but is not limited to this. In this way, by determining whether the tokens are identical, it is possible to determine whether the file read request is safe, thereby improving the security of the information in the sent file.
[0078] Optionally, in the file reading method provided in the embodiments of the present application, all or part of the target information is sent to the browser. The target information may be large in size and exceed the browser's single processing capability. In such a case, the target information may be split into multiple parts for transmission, which can be done without limitation. This avoids browser overload.
[0079] In order to better understand the file reading method in the embodiment of the present application, the file reading method in the embodiment of the present application is explained and illustrated below in combination with optional embodiments, which can be applied to but not limited to the embodiment of the present application.
[0080] Figure 6 is a schematic diagram of an optional file reading method according to an embodiment of the present application, such as Figure 6As shown, the example of reading a file to be uploaded from a file stored in the terminal's operating system may be used, but is not limited to the example. The local file server 102-2 includes a token generation module 102-2-1 and a file reading module 102-2-2. The browser 102-1 may, but is not limited to, allow communication with the local file server. The following steps may be used to read at least part of the information in the file from the local file server:
[0081] In step S702, a user logs in to the client of browser 102-1, triggering a click event on the file read button control on the browser 102-1 page. The local file server 102-2 responds to the click event and prompts the user to select an interactive page to read a local file object. The user selects the file to be read (equivalent to the target file). For example, the user selects the first storage path of the file to be read as "C:\A.txt", and the actual content of the file is "1122334455667788", which is 16 bytes long.
[0082] Step S704, in this case, the local file server 102-2 calculates the token value (equivalent to the first token) according to the file selected by the user, where token = HASH (file storage path + file content + 32-byte random number) value, and the token generation module 102-2-1 in the local file server 102-2 realizes the generation of 32-bit byte random numbers and the calculation of tokens, and saves the mapping relationship between the token value (equivalent to the first token) and the 32-bit byte random number and the file path (equivalent to the first storage path) in the token generation module 102-2-1, and at the same time only returns the token value (equivalent to the first token), the full file path (equivalent to the first storage path) and the total file length (equivalent to the first file length) to the client of the browser 102-1. The HASH algorithm can be but is not limited to the SM3 algorithm, or the SHA256 algorithm, or the SHA384 algorithm or the SHA512 algorithm, etc.
[0083] Specifically, the token generation module 102-2-1 first generates a 32-bit byte random number "B7DA5C48AC5856E767354144E5D9EC547D7FB25CE22C744EBABEE477CF58FEB C", and then calculates token = SHA256("C:\A.txt" + "1122334455667788" + "B7DA5C48AC5856E767354144E5D9EC547D7FB25CE22C744EBABEE477CF58FEB C" through the formula token = HASH(first storage path + file content (equivalent to target information) + 32-bit byte random number). C"); in detail, it can be but not limited to converting "C:\A.txt" ACSII codec to hexadecimal characters to obtain 433A5C412E747874, converting "112233445667788" ACSII codec to hexadecimal characters to obtain 31313232333334343535363637373838, then token = SHA256("C:\A.txt"+"112233445667788"+"B7DA5C48AC5856E767354144E5D9EC547D7FB25CE22C744EB ABEE477CF58FEBC")=SHA256(433A5C412E74787431313232333334343535363637 373838B7DA5C48AC5856E767354144E5D9EC547D7FB25CE22C744EBABEE477CF58FE BC")=7E507D2987CF53F237DCBF696824A89AA7E6D23B83844D469B458E8ED22F358A.
[0084] The token generation module 102-2-1 stores the mapping relationship between the token value, the 32-bit byte random number, and the file storage path in a table of the token generation module 102-2-1, as shown in Table 1:
[0085] Table 1
[0086]
[0087] At the same time, the token value, the full file path, and the total file length are returned to the client of the browser 102 - 1 , and the return value (equivalent to the first return information) is “7E507D2987CF53F237DCBF696824A89AA7E6D23B83844D469B458E8ED22F358A||C:\A.txt||16”.
[0088] Step S706: When the client of the browser 102-1 needs to read a file, the parameter request is sent to the local file server 102-2 in a request manner through an instruction to read the content and length of the specified file.
[0089] Specifically, the parameters include value, file position 0 (equivalent to the first starting position) and length 6 bytes (equivalent to the second file length); the format of the first file read request is: value||0||6.
[0090] In step S708, the local file server 102-2 reads the information in the file according to the parameter token value and the second storage path. In detail, the local file server 102-2 reads the file content according to the token value (equivalent to the second token) in the request parameter request of the browser 102-1 and the second storage path. The token generation module 102-2-1 queries the table of the token generation module 102-2-1 based on the token value (equivalent to the second token) in the parameter value. If the first token that is identical to the second token does not exist in the table of the token generation module 102-2-1, the local file server 102-2 returns an error prompt that no file exists; if the first token that is identical to the second token exists in the table of the token generation module 102-2-1, in this case, the local file server 102-2 searches for the corresponding file path A3 value (equivalent to the first storage path) and A2 value (equivalent to a random number) through the A1 value in the table of the token generation module 102-2-1, and reads at least part of the content value in the file on the second storage path through the file path in the request (equivalent to the second storage path).
[0091] Calculate token2 (equivalent to the third token) = SHA256 (A3 value + content value + A2 value) and compare it with token (equivalent to the first token). If the token value is equal to token2, that is, the first token is the same as the third token. In this case, the local file server 102-2 authorizes and returns the file content "112233" to the browser 102-1.
[0092] The file reading method provided in the embodiment of the present application can indicate that it wishes to read the file on the storage path when the first file reading request sent by the browser is obtained. In this case, the token carried in the first file reading request can be searched from the token set. When a token identical to the token carried in the first file reading request is found, it can be indicated that the current security is sufficient. In this case, at least part of the information in the file is allowed to be sent to the browser. By determining whether the tokens are the same, the information in the file is sent to the browser while ensuring the security of the sending process, thereby avoiding reading the information in the file directly through the storage path of the file, solving the problem of low security of file reading in related technologies, and thus achieving the effect of improving the security of file reading.
[0093] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0094] The present application also provides a file reading device. It should be noted that the file reading device of the present application can be used to execute the file reading method provided in the present application. The following describes the file reading device provided in the present application.
[0095] Figure 7 is a schematic diagram of a file reading device provided according to an embodiment of the present application, such as Figure 7 As shown, the device includes:
[0096] a generating module 702 configured to, when a target file on a first storage path is selected as a file to be uploaded, generate a first token based on the first storage path, target information included in the target file, and a generated random number, wherein the first token has a mapping relationship with the random number and the first storage path, and the first token is stored in a target token set;
[0097] A first processing module 704 is configured to combine the first token, the first storage path, and the first file length of the target file into first return information, and send the first return information to the browser;
[0098] A first obtaining module 706 is configured to obtain a first file reading request sent by the browser;
[0099] A first search module 708 is configured to search for a token identical to the second token in the target token set when a second token is obtained in the first file read request;
[0100] The first sending module 710 is configured to send at least part of the target information to the browser when the first token identical to the second token is found.
[0101] Optionally, in the file reading device provided in an embodiment of the present application, the first search module includes:
[0102] an acquiring unit, configured to, when the first file read request carries second return information, a first starting position, and a second file length, and the second return information includes a second token, acquire the second token included in the second return information, wherein the second file length is less than or equal to the first file length;
[0103] A searching unit is configured to search for a token identical to the second token in the target token set.
[0104] Optionally, in the file reading device provided in an embodiment of the present application, the first sending module includes:
[0105] a processing unit, configured to, when the first token identical to the second token is found and the second return information further includes a second storage path, obtain the second storage path included in the second return information, read information of the second file length starting from the first starting position in the file on the second storage path, and obtain first information to be sent, wherein, when the first storage path and the second storage path are identical, the first information to be sent is at least part of the target information;
[0106] A sending unit is used to send the first information to be sent to the browser.
[0107] Optionally, in the file reading device provided in the embodiment of the present application, the device further includes:
[0108] a second acquiring module, configured to acquire a second file reading request sent by the browser when the first information to be sent is the first part of the target information;
[0109] a third acquiring module, configured to, when the second file read request carries third return information, a second starting position, and a third file length, and the third return information includes the second token, acquire the second token included in the third return information, wherein the third file length is less than the first file length, and the sum of the second file length and the third file length is less than or equal to the first file length;
[0110] A second search module, configured to search for a token identical to the second token in the target token set;
[0111] a second processing module, configured to, when the first token identical to the second token is found and the third return information also includes the second storage path, obtain the second storage path included in the third return information, read information of the third file length starting from the second starting position in the file on the second storage path, and obtain second information to be sent, wherein, when the first storage path and the second storage path are identical, the second information to be sent is second partial information in the target information that is different from the first partial information, and the target information includes the first partial information and the second partial information;
[0112] The second sending module is used to send the second information to be sent to the browser.
[0113] Optionally, in the file reading device provided in the embodiment of the present application, the device further includes:
[0114] a fourth acquiring module, configured to acquire a second file reading request sent by the browser when the first information to be sent is the first part of the target information;
[0115] a fifth acquisition module, configured to, when the second file read request carries third return information and a third file length, and the third return information includes the second token, acquire the second token included in the third return information, wherein the third file length is less than the first file length, and the sum of the second file length and the third file length is less than or equal to the first file length;
[0116] a third search module, configured to search for a token identical to the second token in the target token set;
[0117] a sixth acquiring module, configured to, when the first token identical to the second token is found and the third returned information also includes the second storage path, acquire the second storage path included in the third returned information;
[0118] a determining module, configured to determine a second starting position based on the pre-stored first starting position and the second file length, wherein the second starting position is a next position of the first information to be sent in the file on the second storage path;
[0119] a reading module, configured to read information of the third file length starting from the second starting position in the file on the second storage path to obtain second information to be sent, wherein, if the first storage path and the second storage path are the same, the second information to be sent is the second portion of information in the target information, and the target information includes the first portion of information and the second portion of information;
[0120] The third sending module is used to send the second information to be sent to the browser.
[0121] Optionally, in the file reading device provided in an embodiment of the present application, the sending unit is configured to:
[0122] In a case where the second returned information further includes a second storage path, obtaining information included in a file on the second storage path;
[0123] Acquire the random number and the first storage path having the mapping relationship with the first token;
[0124] Generate a third token based on information included in the files on the first storage path and the second storage path and the random number, wherein the third token is generated in the same manner as the first token;
[0125] When the first token and the third token are identical, the first information to be sent is sent to the browser.
[0126] Optionally, in the file reading device provided in an embodiment of the present application, the processing unit is configured to:
[0127] In a case where the second returned information further includes a second storage path, obtaining information included in a file on the second storage path;
[0128] Acquire the random number and the first storage path having the mapping relationship with the first token;
[0129] Generate a third token based on information included in the files on the first storage path and the second storage path and the random number, wherein the third token is generated in the same manner as the first token;
[0130] In the case that the first token and the third token are the same, information about the length of the second file is read from the first starting position in the file on the second storage path to obtain the first information to be sent.
[0131] Optionally, in the file reading device provided in an embodiment of the present application, the first starting position is used to indicate the position of the first byte to be read, and the second file length is used to indicate the length of bytes read starting from the first starting position.
[0132] The file reading device provided by the embodiment of the present application can indicate that it wishes to read the file on the storage path when it obtains the first file reading request sent by the browser. In this case, the token carried in the first file reading request can be searched from the token set. When a token identical to the token carried in the first file reading request is found, it can be indicated that the current security is sufficient. In this case, at least part of the information in the file is allowed to be sent to the browser. By determining whether the tokens are the same, the information in the file is sent to the browser while ensuring the security of the sending process, thereby avoiding reading the information in the file directly through the storage path of the file, solving the problem of low security of file reading in related technologies, and thus achieving the effect of improving the security of file reading.
[0133] The file reading device includes a processor and a memory. The above units are all stored in the memory as program units, and the processor executes the above program units stored in the memory to realize corresponding functions.
[0134] The processor contains a kernel, which retrieves the corresponding program unit from the memory. One or more kernels can be configured, and the security of file access can be improved by adjusting kernel parameters.
[0135] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0136] An embodiment of the present invention provides a computer-readable storage medium on which a program is stored. When the program is executed by a processor, the file reading method is implemented.
[0137] An embodiment of the present invention provides a processor, which is used to run a program, wherein the file reading method is executed when the program is running.
[0138] Figure 8 is a schematic diagram of an electronic device provided according to an embodiment of the present application, such as Figure 8As shown, an embodiment of the present invention provides an electronic device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, the following steps are implemented: when a target file on a first storage path is selected as a file to be uploaded, a first token is generated according to the first storage path, target information included in the target file, and a generated random number, wherein the first token has a mapping relationship with the random number and the first storage path, and the first token is stored in a target token set; the first token, the first storage path, and the first file length of the target file are combined into first return information, and the first return information is sent to a browser; a first file read request sent by the browser is obtained; when a second token is obtained in the first file read request, a token identical to the second token is searched in the target token set; when the first token identical to the second token is found, at least part of the target information is sent to the browser.
[0139] Optionally, the above-mentioned processor can also implement the following steps when executing the program: when the first file reading request carries second return information, a first starting position and a second file length, and the second return information includes a second token, obtain the second token included in the second return information, wherein the second file length is less than or equal to the first file length; search for a token that is the same as the second token in the target token set.
[0140] Optionally, the processor may further implement the following steps when executing the program: when the first token identical to the second token is found and the second return information also includes a second storage path, obtaining the second storage path included in the second return information, reading the information of the second file length starting from the first starting position in the file on the second storage path, and obtaining the first information to be sent, wherein, when the first storage path and the second storage path are the same, the first information to be sent is at least part of the target information; and sending the first information to be sent to the browser.
[0141] Optionally, the processor may further implement the following steps when executing the program: when the first information to be sent is the first part of the target information, obtaining a second file read request sent by the browser; when the second file read request carries third return information, a second starting position and a third file length, and the third return information includes the second token, obtaining the second token included in the third return information, wherein the third file length is less than the first file length, and the sum of the second file length and the third file length is less than or equal to the first file length; searching for a token identical to the second token in the target token set; when the first token identical to the second token is found, and the third return information also includes the second storage path, obtaining the second storage path included in the third return information, reading information of the third file length starting from the second starting position in the file on the second storage path, and obtaining second information to be sent, wherein, when the first storage path and the second storage path are the same, the second information to be sent is the second part of the target information that is different from the first part of the information, and the target information includes the first part of the information and the second part of the information; and sending the second information to be sent to the browser.
[0142] Optionally, the processor may further implement the following steps when executing the program: in a case where the first information to be sent is the first part of the target information, obtaining a second file reading request sent by the browser; in a case where the second file reading request carries third return information and a third file length, and the third return information includes the second token, obtaining the second token included in the third return information, wherein the third file length is less than the first file length, and the sum of the second file length and the third file length is less than or equal to the first file length; searching for a token identical to the second token in the target token set; and when the first token identical to the second token is found, and the third return information also includes the second token. In the case where the second storage path is included, the second storage path included in the third return information is obtained; a second starting position is determined according to the pre-stored first starting position and the second file length, wherein the second starting position is the next position of the first information to be sent in the file on the second storage path; information of the third file length is read from the second starting position in the file on the second storage path to obtain second information to be sent, wherein, in the case where the first storage path and the second storage path are the same, the second information to be sent is the second part of the target information, and the target information includes the first part of the information and the second part of the information; and the second information to be sent is sent to the browser.
[0143] Optionally, the processor may further implement the following steps when executing the program: when the second return information also includes a second storage path, obtaining information included in the file on the second storage path; obtaining the random number and the first storage path having the mapping relationship with the first token; generating a third token based on the first storage path, the information included in the file on the second storage path, and the random number, wherein the third token is generated in the same manner as the first token; and when the first token and the third token are the same, sending the first information to be sent to the browser.
[0144] Optionally, the processor may further implement the following steps when executing the program: when the second return information also includes a second storage path, obtain the information included in the file on the second storage path; obtain the random number and the first storage path having the mapping relationship with the first token; generate a third token based on the first storage path, the information included in the file on the second storage path, and the random number, wherein the generation method of the third token is the same as the generation method of the first token; when the first token and the third token are the same, read the information of the length of the second file starting from the first starting position in the file on the second storage path to obtain the first information to be sent.
[0145] Optionally, the processor may further implement the following steps when executing the program: the first starting position is used to indicate the position of the first byte to be read, and the second file length is used to indicate the length of bytes read starting from the first starting position.
[0146] The devices in this article can be servers, PCs, PADs, mobile phones, etc.
[0147] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program initialized with the following method steps: when a target file on a first storage path is selected as a file to be uploaded, generating a first token based on the first storage path, target information included in the target file, and a generated random number, wherein the first token has a mapping relationship with the random number and the first storage path, and the first token is stored in a target token set; forming first return information with the first token, the first storage path, and the first file length of the target file, and sending the first return information to a browser; obtaining a first file read request sent by the browser; when a second token is obtained in the first file read request, searching for a token identical to the second token in the target token set; when the first token identical to the second token is found, sending at least part of the target information to the browser.
[0148] Optionally, the above-mentioned computer program product, when executed on a data processing device, is suitable for executing a program initialized with the following method steps: when the first file reading request carries second return information, a first starting position and a second file length, and the second return information includes a second token, obtaining the second token included in the second return information, wherein the second file length is less than or equal to the first file length; and searching for a token identical to the second token in the target token set.
[0149] Optionally, the above-mentioned computer program product, when executed on a data processing device, is suitable for executing an initialization program having the following method steps: when the first token identical to the second token is found and the second return information also includes a second storage path, obtaining the second storage path included in the second return information, reading the information of the second file length starting from the first starting position in the file on the second storage path, and obtaining the first information to be sent, wherein, when the first storage path and the second storage path are the same, the first information to be sent is at least part of the target information; and sending the first information to be sent to the browser.
[0150] Optionally, the above-mentioned computer program product, when executed on a data processing device, is suitable for executing a program initialized with the following method steps: when the first information to be sent is the first part of the target information, obtaining a second file read request sent by the browser; when the second file read request carries third return information, a second starting position and a third file length, and the third return information includes the second token, obtaining the second token included in the third return information, wherein the third file length is less than the first file length, and the sum of the second file length and the third file length is less than or equal to the first file length; searching for a token identical to the second token in the target token set; when the first token identical to the second token is found and the third return information also includes the second storage path, obtaining the second storage path included in the third return information, reading information of the third file length starting from the second starting position in the file on the second storage path, and obtaining second information to be sent, wherein, when the first storage path and the second storage path are the same, the second information to be sent is the second part of the target information that is different from the first part of the information, and the target information includes the first part of the information and the second part of the information; and sending the second information to be sent to the browser.
[0151] Optionally, the above-mentioned computer program product, when executed on a data processing device, is suitable for executing a program initialized with the following method steps: in a case where the first information to be sent is the first part of the target information, obtaining a second file reading request sent by the browser; in a case where the second file reading request carries third return information and a third file length, and the third return information includes the second token, obtaining the second token included in the third return information, wherein the third file length is less than the first file length, and the sum of the second file length and the third file length is less than or equal to the first file length; searching for a token identical to the second token in the target token set; and when the first token identical to the second token is found, When the third return information also includes the second storage path, the second storage path included in the third return information is obtained; a second starting position is determined based on the pre-stored first starting position and the second file length, wherein the second starting position is the next position of the first information to be sent in the file on the second storage path; information of the third file length is read from the second starting position in the file on the second storage path to obtain second information to be sent, wherein, when the first storage path and the second storage path are the same, the second information to be sent is the second part of the target information, and the target information includes the first part of the information and the second part of the information; and the second information to be sent is sent to the browser.
[0152] Optionally, the above-mentioned computer program product, when executed on a data processing device, is suitable for executing a program initialized with the following method steps: when the second return information also includes a second storage path, obtaining the information included in the file on the second storage path; obtaining the random number and the first storage path that have the mapping relationship with the first token; generating a third token based on the first storage path, the information included in the file on the second storage path, and the random number, wherein the generation method of the third token is the same as the generation method of the first token; and when the first token and the third token are the same, sending the first information to be sent to the browser.
[0153] Optionally, the above-mentioned computer program product, when executed on a data processing device, is suitable for executing a program initialized with the following method steps: when the second return information also includes a second storage path, obtaining the information included in the file on the second storage path; obtaining the random number and the first storage path that have the mapping relationship with the first token; generating a third token based on the first storage path, the information included in the file on the second storage path, and the random number, wherein the generation method of the third token is the same as the generation method of the first token; when the first token and the third token are the same, reading the information of the length of the second file starting from the first starting position in the file on the second storage path to obtain the first information to be sent.
[0154] Optionally, the above-mentioned computer program product, when executed on a data processing device, is suitable for executing an initialization program having the following method steps: the first starting position is used to indicate the position of the first byte to be read, and the second file length is used to indicate the length of the bytes read starting from the first starting position.
[0155] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0156] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0157] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0158] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0159] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0160] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0161] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0162] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0163] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0164] The above are merely embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.
Claims
1. A file reading method, characterized in that: include: When a target file on a first storage path is selected as a file to be uploaded, generating a first token according to the first storage path, target information included in the target file, and a generated random number, wherein the first token has a mapping relationship with the random number and the first storage path, and the first token is stored in a target token set; Combining the first token, the first storage path and the first file length of the target file into first return information, and sending the first return information to the browser; Obtaining a first file reading request sent by the browser; When a second token is obtained in the first file read request, searching for a token identical to the second token in the target token set; In the case where the first token identical to the second token is found, at least part of the target information is sent to the browser.
2. The method according to claim 1, characterized in that In the case where a second token is obtained in the first file read request, searching for a token identical to the second token in the target token set includes: When the first file read request carries second return information, a first starting position, and a second file length, and the second return information includes a second token, obtaining the second token included in the second return information, wherein the second file length is less than or equal to the first file length; A token identical to the second token is searched in the target token set.
3. The method according to claim 2, characterized in that The step of sending at least part of the target information to the browser when the first token identical to the second token is found includes: When the first token identical to the second token is found and the second return information further includes a second storage path, obtaining the second storage path included in the second return information, reading information of the second file length from the first starting position in the file on the second storage path, and obtaining first information to be sent, wherein, when the first storage path and the second storage path are identical, the first information to be sent is at least part of the target information; The first information to be sent is sent to the browser.
4. The method according to claim 3, characterized in that The method further comprises: When the first information to be sent is the first part of the target information, obtaining a second file reading request sent by the browser; When the second file read request carries third return information, a second starting position, and a third file length, and the third return information includes the second token, obtaining the second token included in the third return information, wherein the third file length is less than the first file length, and the sum of the second file length and the third file length is less than or equal to the first file length; Searching for a token identical to the second token in the target token set; When the first token identical to the second token is found and the third returned information also includes the second storage path, obtaining the second storage path included in the third returned information, reading information of the third file length starting from the second starting position in the file on the second storage path, and obtaining second information to be sent, wherein, when the first storage path and the second storage path are identical, the second information to be sent is the second partial information of the target information that is different from the first partial information, and the target information includes the first partial information and the second partial information; The second information to be sent is sent to the browser.
5. The method according to claim 3, characterized in that The method further comprises: When the first information to be sent is the first part of the target information, obtaining a second file reading request sent by the browser; When the second file read request carries third return information and a third file length, and the third return information includes the second token, obtaining the second token included in the third return information, wherein the third file length is less than the first file length, and the sum of the second file length and the third file length is less than or equal to the first file length; Searching for a token identical to the second token in the target token set; When the first token identical to the second token is found and the third returned information also includes the second storage path, acquiring the second storage path included in the third returned information; Determining a second starting position according to the pre-stored first starting position and the second file length, wherein the second starting position is a next position of the first information to be sent in the file on the second storage path; Reading information of the third file length from the second starting position in the file on the second storage path to obtain second information to be sent, wherein, if the first storage path and the second storage path are the same, the second information to be sent is the second portion of the target information, and the target information includes the first portion of the information and the second portion of the information; The second information to be sent is sent to the browser.
6. The method according to claim 3, characterized in that The sending the first information to be sent to the browser includes: In a case where the second returned information further includes a second storage path, obtaining information included in a file on the second storage path; Acquire the random number and the first storage path having the mapping relationship with the first token; Generate a third token based on information included in the files on the first storage path and the second storage path and the random number, wherein the third token is generated in the same manner as the first token; When the first token and the third token are identical, the first information to be sent is sent to the browser.
7. The method according to claim 3, characterized in that The step of reading information about the length of the second file from the first starting position in the file on the second storage path to obtain first information to be sent includes: In a case where the second returned information further includes a second storage path, obtaining information included in a file on the second storage path; Acquire the random number and the first storage path having the mapping relationship with the first token; Generate a third token based on information included in the files on the first storage path and the second storage path and the random number, wherein the third token is generated in the same manner as the first token; In the case that the first token and the third token are the same, information about the length of the second file is read from the first starting position in the file on the second storage path to obtain the first information to be sent.
8. The method according to any one of claims 2 to 7, characterized in that The first starting position is used to indicate the position of the first byte to be read, and the second file length is used to indicate the length of bytes to be read starting from the first starting position.
9. A file reading device, characterized in that: include: a generating module, configured to, when a target file on a first storage path is selected as a file to be uploaded, generate a first token based on the first storage path, target information included in the target file, and a generated random number, wherein the first token has a mapping relationship with the random number and the first storage path, and the first token is stored in a target token set; a first processing module, configured to combine the first token, the first storage path, and the first file length of the target file into first return information, and send the first return information to the browser; A first acquisition module, configured to acquire a first file reading request sent by the browser; a first search module configured to search for a token identical to the second token in the target token set when a second token is obtained in the first file read request; The first sending module is configured to send at least part of the target information to the browser when the first token identical to the second token is found.
10. A processor, characterized in that: The processor is configured to run a program, wherein the program executes the method according to any one of claims 1 to 8 when running.
11. An electronic device, characterized in that: The method comprises one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Access control method, device and system for encrypted traffic
CN116074028A
Permission control method, server, terminal, storage medium, and computer program
WO2022193494A1