Method and device for downloading file through browser and electronic equipment
By splitting files into sub-sections and asynchronously downloading storage shards, the problem of uncontrollable browser file download progress is solved, real-time monitoring and display of download progress is achieved, and user experience and efficiency are improved.
Patent Information
- Application Number
- CN202410627879.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-20
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2044-05-20
AI Technical Summary
Existing browser file download methods lack progress controllability and user experience, and cannot monitor download progress in real time, affecting user experience.
By receiving file download instructions, the file size is obtained, split into sub-intervals, asynchronously downloaded and stored into the preset database, monitors the progress of the fragments in real time, and provides download progress information.
It improves the controllability and user experience of downloading files by the browser, displays the download progress in real time, reduces the frequency of requests to the server, and reduces the network load.
Smart Images

Figure CN118540319A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data transmission technology, and in particular to the field of information content processing and browser technology. Background Art
[0002] With the rapid development of World Wide Web (Web) application services and the increasing maturity of Internet technology, file download has become one of the core functions of network services and occupies an important position in front-end development practice. At present, there are two mainstream ways to download files: download through a browser and download through a client. Summary of the invention
[0003] The present disclosure provides a method, device and electronic device for downloading files through a browser.
[0004] According to a first aspect of the present disclosure, a method for downloading a file through a browser is provided, which is applied to the browser and includes:
[0005] Receiving a file download instruction, wherein the file download instruction is used to instruct to download a target file;
[0006] Obtaining the file size of the target file, determining the file interval of the target file according to the file size, and splitting the file interval into multiple sub-intervals, wherein the maximum value of the file interval is the file size;
[0007] The target segments corresponding to each subinterval in the target file are downloaded from the first server respectively, the downloaded target segments are stored in a preset database, and the target segments stored in the preset database are asynchronously monitored, and the download progress of the target file is determined according to the target segments stored in the preset database.
[0008] According to a second aspect of the present disclosure, there is provided a device for downloading a file through a browser, which is applied to the browser and includes:
[0009] A receiving module, used for receiving a file download instruction, wherein the file download instruction is used for instructing to download a target file;
[0010] A splitting module, used for obtaining the file size of the target file, determining the file interval of the target file according to the file size, and splitting the file interval into a plurality of sub-intervals, wherein the maximum value of the file interval is the file size;
[0011] A download module is used to download the target segments corresponding to each sub-interval in the target file from the first server respectively, store the downloaded target segments in a preset database, and asynchronously monitor the target segments stored in the preset database, and determine the download progress of the target file according to the target segments stored in the preset database.
[0012] According to a third aspect of the present disclosure, there is provided an electronic device, including:
[0013] at least one processor; and
[0014] a memory communicatively connected to the at least one processor; wherein,
[0015] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform any method according to the first aspect.
[0016] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause the computer to execute the method according to any one of the first aspect.
[0017] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the method according to any one of the first aspects.
[0018] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0020] Figure 1 is a flow chart of a method for downloading files through a browser provided by an embodiment of the present disclosure;
[0021] Figure 2 is a flow chart of a segment downloading method provided by an embodiment of the present disclosure;
[0022] Figure 3 is a flow chart of a file transfer method provided by an embodiment of the present disclosure;
[0023] Figure 4 is an exemplary schematic diagram of a process of downloading a file through a browser provided by an embodiment of the present disclosure;
[0024] Figure 5is an exemplary schematic diagram of another process of downloading a file through a browser provided by an embodiment of the present disclosure;
[0025] Figure 6 is a schematic diagram of the structure of a device for downloading files through a browser provided by an embodiment of the present disclosure;
[0026] Figure 7 The present invention is a block diagram of an electronic device for implementing the method for downloading files through a browser according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0027] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0028] Currently, there are two mainstream ways to download files: downloading through a browser and downloading through a client. Although the purpose of downloading files through a browser and downloading files through a client is the same, that is, both are to transfer files from a remote server to a local device, there are significant differences between these two file downloading methods in terms of implementation mechanism, user experience, and optimization direction.
[0029] Downloading files through the client means downloading files through special download management software or applications. This method can usually effectively utilize network bandwidth, provide relatively stable and reliable download services, and support rich download functions, such as multi-threaded downloading, breakpoint resumption, download speed control, and file storage location management. This download method also has a high degree of visualization and user controllability. For example, it can display real-time download progress for users, allow users to adjust download strategies and manage downloaded files, etc. This download method can provide users with a good download experience. However, this download method is also accompanied by obvious defects. For example, if a user wants to download a video, he needs to install the video software in the terminal first before he can download the video through the video software; if a user wants to download a song, he needs to install the music software in the terminal first before he can download the song through the music software. For another example, a user wants to download the exclusive video of video software A. Since the exclusive video is only provided by video software A and cannot be provided by other video software, even if other video software is installed in the terminal, the exclusive video cannot be downloaded through other video software. Therefore, video software A needs to be installed in the terminal before the exclusive video can be downloaded through video software A. It can be seen that when downloading files through the client, different types of files and files from different sources need to be downloaded using different software, so the installation time cost is high, which is a threshold that cannot be ignored for users who are looking for a simple and fast download experience.
[0030] Downloading files through a browser is a way to download files inside a web browser. This method does not require the installation of additional software in the terminal to download various types of files. For example, videos, songs, texts, and application installation packages can be downloaded through the browser, which is highly convenient. However, the traditional browser download process is essentially a one-way and non-interactive data transmission mode, that is, when the browser needs to download a file, it calls the preset download interface, and the download manager corresponding to the download interface downloads the file. Once the download starts, the entire download process is unknown and uncontrollable to the browser. Therefore, the browser cannot determine the download progress of the file, and cannot provide the user with the download progress of the file. This invisibility restricts the user's understanding of the download process and affects the user's download experience.
[0031] In order to improve the user experience of downloading files through a browser, the embodiment of the present disclosure provides a method for downloading files through a browser, which is applied to a browser. The browser is installed in a terminal, for example, the terminal can be an electronic device with network communication and data processing capabilities such as a mobile phone, a tablet computer, a laptop computer or a desktop computer.
[0032] like Figure 1 As shown, the method for downloading files through a browser provided by the embodiment of the present disclosure includes the following steps:
[0033] S101. Receive a file download instruction, where the file download instruction is used to instruct to download a target file.
[0034] The browser can display a web page and detect a file download instruction triggered by a user in the web page. Optionally, the file download instruction can be triggered by clicking a download button or voice control. For example, when the browser displays a video web page, the user interface (UI) includes a download button or download link for the video. When the browser detects that the user clicks the video download button or download link, the file download instruction for the video is triggered.
[0035] The target file may be a video, audio, text or software installation package, etc., which is not specifically limited in the embodiments of the present disclosure.
[0036] S102: Obtain the file size of the target file, determine the file interval of the target file according to the file size, and split the file interval into multiple sub-intervals, wherein the maximum value of the file interval is the file size.
[0037] For example, assuming that the file size of the target file is 500 bytes, the file interval can be [0,500], and the multiple sub-intervals obtained by splitting the file interval can be: [0,100), [100,200), [200,300), [300,400) and [400,500].
[0038] S103, respectively downloading target segments corresponding to each sub-interval in the target file from the first server, storing the downloaded target segments in a preset database of the browser, and asynchronously monitoring the target segments stored in the preset database, and determining the download progress of the target file according to the target segments stored in the preset database.
[0039] In order to realize asynchronous processing, the browser can download the target segments in each sub-interval of the target file from the first server through the first thread, store the downloaded target segments in the preset database of the browser, and monitor the target segments stored in the preset database through the second thread, determine the download progress of the target file according to the target segments stored in the preset database, and display the download progress. The first thread and the second thread are executed asynchronously.
[0040] The preset database may be an indexed database (Indexed Database, IndexedDB).
[0041] The browser can obtain the download link of the target file from the web page, analyze the domain name of the first server from the download link, and then obtain the Internet Protocol (IP) address of the first server through domain name resolution, and then communicate with the first server based on the IP address of the first server.
[0042] Since in the disclosed embodiment, the browser can store each target segment downloaded from the first server in a preset database, the download progress of the target file can be obtained by monitoring the target segment stored in the preset database. It can be seen that for the browser, the storage location of the target segment is known, so by monitoring the segment situation stored in the storage location, the downloaded part of the target file can be obtained, that is, the real-time download progress is obtained, and the controllability of the browser over the file download process is improved, so as to provide users with real-time download progress and enhance the user's download experience.
[0043] The following is a detailed description of the method for downloading files through a browser provided in an embodiment of the present disclosure.
[0044] In some embodiments of the present disclosure, the method in which the browser obtains the file size of the target file in S102 includes the following steps:
[0045] Step 1: Send a metadata acquisition request to the first server, wherein the metadata acquisition request is used to request metadata of a target file.
[0046] The metadata of the target file is data describing the attributes of the target file. For example, the metadata of the target file includes: file size, type, name, etc.
[0047] Step 2: Receive a metadata acquisition response sent by the first server, and extract the file size of the target file from the metadata of the target file included in the metadata acquisition response.
[0048] It should be noted that the metadata acquisition request and the metadata acquisition response may be based on Hypertext Transfer Protocol (HTTP) or Hypertext Transfer Protocol Secure (HTTPS) and the like.
[0049] The browser can obtain metadata of the target file from the first server, including the file size of the target file, so that the file interval can be accurately split based on the file size later, providing a basis for segmented downloading of the target file.
[0050] Before the above S102, the browser may also perform an authentication process to improve the security of the transmission and storage of the target file. The authentication process includes: the browser sends an authentication request to the second server, wherein the authentication request is used to request the second server to identify whether the browser has the authority to download the target file, and then the browser receives an authentication response sent by the second server.
[0051] The browser may obtain the domain name of the second server used for authentication from the web page, then obtain the IP address of the second server through domain name resolution, and then communicate with the second server based on the IP address of the second server.
[0052] The authentication request includes: the file name of the target file and identity verification information. For example, the identity verification information includes at least one of the following data or a combination of any multiple data: the user name of the browser's logged-in user, the token identity document (token ID), and the device ID of the terminal where the browser is located, etc., which is not specifically limited in the embodiments of the present disclosure.
[0053] After receiving the authentication request, the second server can determine the target file corresponding to the file name of the target file and obtain a download whitelist of the target file, wherein the download whitelist includes identity authentication information with the authority to download the target file. The browser then checks whether the identity authentication information included in the authentication request is in the download whitelist of the target file. If so, it is determined that the authentication is passed, that is, the browser has the authority to download the target file; if not, it is determined that the authentication is not passed, that is, the browser does not have the authority to download the target file.
[0054] In the disclosed embodiment, the download whitelist of the target file may be preset. For example, if the target file is a confidential file of an organization, the second server may pre-receive the identity authentication information of each member of the organization uploaded by the organization, and form the received identity authentication information into the download whitelist of the target file.
[0055] For another example, if the target file is paid content, the second server may add the user's identity authentication information to the target file download whitelist after the user successfully purchases the target file.
[0056] In another implementation, after receiving the authentication request, the browser can determine the target file corresponding to the file name of the target file, and obtain a download blacklist of the target file, wherein the download blacklist includes identity authentication information that does not allow the target file to be downloaded. The browser then checks whether the identity authentication information included in the authentication request is in the download blacklist of the target file. If so, it is determined that the authentication fails; if not, it is determined that the authentication passes.
[0057] The download blacklist of the target file may be preset. For example, the second server may obtain identity authentication information with malicious download risk, and form the download blacklist of the target file with the obtained identity authentication information.
[0058] The authentication response returned by the second server to the browser includes an authentication result field. For example, if the authentication result field is 1, it means that the authentication is passed, and if the authentication result field is 0, it means that the authentication is not passed.
[0059] It should be noted that the first server and the second server may be physically the same server or different servers. The authentication request and the authentication response may be based on HTTP or HTTPS.
[0060] After the authentication process is completed, the way in which the browser sends a metadata acquisition request to the first server in S102 can be implemented as follows: if the authentication response indicates that the browser has the authority to download the target file, then sending a metadata acquisition request to the first server.
[0061] Through the above method, the browser can first request the second server for authentication, and only start the download process when the second server authenticates the browser as having the download authority for the target file, and then obtain the file size of the target file from the first server. This improves the security of target file transmission and reduces the risk of the target file being maliciously acquired.
[0062] In the embodiment of the present disclosure, when any target segment of the target file is not stored in the preset database, in order to download the complete target file, the minimum value of the file interval of the target file can be set to 0, that is, the file interval is [0, file size].
[0063] Through the above method, the browser can download the target file in segments starting from 0, which not only improves the download speed of the target file, but also ensures the integrity of the downloaded target file.
[0064] Alternatively, in the case where a portion of the target fragments of the target file has been stored in the preset database, in order to achieve breakpoint resume, the embodiment of the present disclosure may set the minimum value of the file interval to be: the maximum value of the subinterval corresponding to the target fragment with the largest index in the preset database + 1. For example, if the subinterval corresponding to the target fragment with the largest index in the preset database is [50, 60], then the file interval for breakpoint resume is set to [61, the file size of the target file].
[0065] For the specific method of breakpoint resume, please refer to the description below.
[0066] In the above S102, the browser divides the file interval into multiple sub-intervals in the following two ways:
[0067] The first method of splitting the file interval is to split according to the preset fragment size, that is, the browser obtains the preset fragment size, and then in the file interval, starts from the minimum value of the file interval and sequentially intercepts multiple sub-intervals according to the preset fragment size. Among them, there is no intersection between the sub-intervals, and the union of the sub-intervals is the file interval.
[0068] For example, assuming that the size of the target file is 300 bytes and the preset fragment size is 100, the file interval can be [0,300], and the multiple sub-intervals obtained by splitting the file interval are: [0,100), [100,200), [200,300].
[0069] The preset slice size is preconfigured in the browser, and the preset slice size can be set according to network conditions, the response capability of the first server and / or the processing efficiency of the browser.
[0070] In this way, the browser can control the size of each sub-interval not to exceed the preset segment size, that is, control the size of each target segment downloaded not to exceed the preset segment size, thereby optimizing the use of network resources and improving the transmission efficiency of a single target segment.
[0071] Since the file size of the target file is not necessarily an integer multiple of the preset fragment size, the interval size of the last sub-interval obtained by the splitting method of the file interval is smaller than the preset fragment size. In this case, the browser can sequentially intercept multiple sub-intervals in the file interval from the minimum value of the file interval according to the preset fragment size, and then determine whether the interval size of the last sub-interval is smaller than the preset minimum interval size. The minimum interval size can be set according to actual needs, for example, the minimum interval size is 10% of the preset fragment size.
[0072] If the interval size of the last subinterval is less than the preset minimum interval size, the browser merges the second-to-last subinterval and the last subinterval. Conversely, if the interval size of the last subinterval is greater than or equal to the preset minimum interval size, the browser can maintain the subintervals split in the first manner.
[0073] For example, assuming that the size of the target file is 305 bytes and the preset fragment size is 100 bytes, the file interval can be [0,305]. The multiple sub-intervals obtained by splitting the file interval are: [0,100), [100,200), [200,300), [300,305]. Since the interval size of the last sub-interval is less than 10, the second to last sub-interval and the last sub-interval are merged to obtain the sub-intervals: [0,100), [100,200), [200,305].
[0074] In a network environment with low network speed, the more frequently the browser requests the server to download fragments with smaller data volumes, the higher the risk of fragment download failure. Therefore, in the embodiment of the present disclosure, when the interval size of the last sub-interval is smaller than the preset minimum interval size, the second-to-last sub-interval and the last sub-interval are merged to increase the data volume of the target fragment corresponding to the sub-interval, avoid requesting the first server for a target fragment with too small data volume, reduce the risk of fragment download failure, and improve the download success rate of the target file.
[0075] The second way to split the file interval is to split it according to the preset number of fragments, that is, the browser obtains the preset number of fragments and divides the file interval into sub-intervals of the preset number of fragments. There is no intersection between the sub-intervals, and the union of the sub-intervals is the file interval.
[0076] The preset number of slices is preconfigured in the browser, and the preset number of slices can be set according to network conditions, the response capability of the first server and / or the processing efficiency of the browser.
[0077] The interval sizes of the preset number of fragments obtained by division can be the same, that is, the browser can evenly divide the file interval into the preset number of sub-intervals. For example, assuming that the size of the target file is 300 bytes and the preset number of fragments is 3, the file interval can be [0,300], and the multiple sub-intervals obtained by splitting the file interval are: [0,100), [100,200), [200,300].
[0078] Alternatively, the interval sizes of the preset number of fragments obtained by division may not be exactly the same. That is, the browser can calculate the ratio of the file size to the preset number of fragments, and when the ratio is not an integer, round the ratio up or down, and use the rounded result as the fragment size. After that, the browser will intercept multiple sub-intervals in the file interval starting from 0 according to the preset fragment size, and merge the second to last sub-interval with the last sub-interval. For example, assuming that the size of the target file is 400 bytes and the preset number of fragments is 3, in Indicates rounding up. In this case, the file interval can be [0,400]. The fragment size is 133. The multiple sub-intervals obtained by splitting are: [0,133), [133,266), [266,399), [399,400]. The last two sub-intervals are merged to obtain: [0,133), [133,266), [266,400].
[0079] Through the above method, the browser can control the number of target segments requested to be downloaded from the first server, that is, control the number of requests, avoid requesting to download target segments from the first server too frequently, and reduce the risk of processing errors or downtime caused by the first server being in a high concurrency state.
[0080] In addition to the above two file interval splitting methods, the file interval may also be split in other ways, which are not specifically limited in the embodiments of the present disclosure.
[0081] For example, the browser can determine whether the file size of the target file is greater than a preset threshold. If so, the above-mentioned method of splitting according to the preset number of fragments is adopted, that is, the preset number of fragments is obtained, and the file interval is divided into the preset number of fragment sub-intervals to control the number of sub-intervals obtained by splitting, so as to avoid too frequent requests to the first server to download the target fragment. If not, the above-mentioned method of splitting according to the preset fragment size is adopted, that is, the preset fragment size is obtained, and then multiple sub-intervals are intercepted in sequence from 0 in the file interval according to the preset fragment size to control the size of each sub-interval and improve the download speed of the sub-interval.
[0082] In some embodiments of the present disclosure, see Figure 2 , the above-mentioned S103 browser downloads the target fragments corresponding to each sub-interval in the target file from the first server respectively, including:
[0083] S201. For each sub-interval, send a segment download request to a first server, wherein the segment download request is used to request downloading a target segment corresponding to the sub-interval in a target file.
[0084] The segment download request in the embodiment of the present disclosure may be based on HTTP or HTTPS. The request header of the segment download request includes a range field, which is used to indicate the data range of the target segment requested to be downloaded in the target file. For example, the range field includes {start: 0, end: 10}, indicating that the data range of the target segment requested to be downloaded in the target file is bytes 0 to 10.
[0085] The request header of the segment download request may also include other fields. For example, Content-Type, Content-Disposition, and Content-Length. Content-Type is used to indicate the type of the target file. Content-Disposition is used to indicate the download method of the target file, where the download method indicates downloading to the local computer. Content-Length indicates the file size of the target file.
[0086] Optionally, the browser can send a segment download request corresponding to each sub-interval to the first server at the same time. In this way, the download of each target segment included in the target file can be performed almost simultaneously, which greatly improves the file download speed.
[0087] Alternatively, the browser may send the segment download request corresponding to each sub-interval to the first server in sequence according to the arrangement order of the sub-intervals in the file interval.
[0088] Alternatively, the browser may send a specified number of subintervals corresponding to the first server for segment download requests at intervals of a certain length, which is not specifically limited in the embodiments of the present disclosure. The specified number may be pre-set, or may be determined based on the download speed of the browser. For example, the browser may pre-store the number of parallel downloads corresponding to various download speed ranges, and the browser may obtain the current download speed, determine the download speed range to which the current download speed belongs, and then search for the number of parallel downloads corresponding to the download speed range as the specified number.
[0089] S202: Receive a segment download response sent by the first server, and extract a target segment corresponding to the sub-interval from the segment download response.
[0090] The segment download response in the embodiment of the present disclosure may be based on HTTP or HTTPS, and the segment download response includes the target segment corresponding to the sub-interval.
[0091] Through the above method, the browser can download the target file in segments, and the target segments of the target file can be downloaded in parallel, reducing the amount of data downloaded in a single request and increasing the file download speed. At the same time, since the target file is downloaded in segments, the browser can more clearly obtain the downloaded and undownloaded parts, making it easier to monitor and manage the download process.
[0092] In some embodiments of the present disclosure, the first server can split the target file in the manner of splitting the file interval into multiple sub-intervals to obtain multiple target fragments included in the target file and obtain an index of each target fragment, wherein the index is used to indicate the position of the target fragment in the target file.
[0093] The segment download response sent by the first server to the browser in S202 also includes the index of the target segment. Based on this, the browser in S103 stores the downloaded target segment in the preset database by storing the target segment and the index included in the segment download response in the preset database.
[0094] By recording the target segments and their indexes in the preset database, it is easier for the browser to monitor and manage the download process of the target file, providing a basis for functions such as breakpoint resumption, download progress monitoring and integrity verification.
[0095] Optionally, in addition to the index of the target segment, the segment download response may also include other metadata of the target segment, such as the size of the target segment, and the other metadata may also be stored in a preset database corresponding to the target segment.
[0096] The browser constructs a data model including a download task table and a shard information table in a preset database. The download task table records the unique identifier of the download task for the target file, i.e., the download task identifier, as well as the metadata and download status of the target file corresponding to the download task identifier. The shard information table records the download task identifier, as well as the metadata, download status, and storage key of each target shard corresponding to the download task identifier. The storage key is used to indicate the storage location of the target shard in the preset database.
[0097] The download status includes: not downloaded, downloading and download completed. The download status of the target file and the download status of the target segment stored in the preset database are maintained by the browser. When the browser does not send a segment download request for any target segment to the first server, it can be determined that the download status of the target file is not downloaded; when a segment download request for any target segment has been sent to the first server, it can be determined that the download status of the target file is downloading; when all target segments are stored in the preset database, it can be determined that the download status of the target file is download completed. For each target segment, when the browser does not send a segment download request corresponding to the target segment to the first server, it can be determined that the download status of the target segment is not downloaded; when a segment download request corresponding to the target segment has been sent to the first server, it can be determined that the download status of the target segment is downloading; when the target segment is stored in the preset database, it can be determined that the download status of the target segment is download completed.
[0098] Based on this, when the browser monitors the preset database, it can use the download task table and the fragment information table to distinguish the target fragments included in different target files. That is, the browser can determine the download task identifier corresponding to each target file based on the download task table, and determine the target fragment corresponding to each download task identifier based on the fragment information table, thereby obtaining the target fragment included in each target file.
[0099] In the disclosed embodiment, the browser can also perform integrity verification on each downloaded target segment after each target segment of the target file is downloaded. The implementation method includes: monitoring the number of target segments of the target file stored in the preset database, and when the number of target segments of the stored target file reaches the number of sub-intervals divided by the file interval of the target file in S102, it is determined that the download of each target segment of the target file is completed. At this time, the index of each target segment can be sorted, and it is checked whether there is an omission in the index of each target segment. For example, the indexes of each target segment are: 1, 2, 4, 5, then there is a missing index 3 between 2 and 4. If there is no omission, it is determined that the data integrity verification has passed. Otherwise, it is determined that the data integrity verification has not passed, and a prompt message can be displayed to prompt the user that the download has failed, or the target file can be re-downloaded using the above method, or the first server can be re-requested to download the missing target segment.
[0100] This method can verify the integrity of each target segment downloaded, ensuring the efficiency, reliability and integrity of the download process for the target file.
[0101] Moreover, the browser in the embodiment of the present disclosure also supports the user to set the file download priority. The browser can download multiple target files at the same time, and the download method of each target file is the same, which can be referred to the above description. The browser can receive the user's priority setting instruction before downloading multiple target files, or in the process of downloading multiple target files, wherein the priority setting instruction includes the priority of each target file, and the priority of each target file is different. For example, the user can click the download control corresponding to each target file in the browser in turn, and the browser uses the order in which the user clicks the download control as the priority of the target file corresponding to each download control; or the browser can receive the priority of each target file input by the user, which is not specifically limited in the embodiment of the present disclosure. Afterwards, the browser can allocate transmission bandwidth for each target file in order from high to low priority of each target file, wherein the priority of the target file is positively correlated with the allocated transmission bandwidth, and download the target fragments included in the target file from the first server according to the transmission bandwidth allocated to each target file.
[0102] In some embodiments of the present disclosure, the above-mentioned S103 browser determines the download progress of the target file according to the target segment stored in the preset database, including the following steps:
[0103] Step 1: Get the maximum index among the indexes of the target shard stored in the preset database.
[0104] The browser may search for the download task identifier of the download task for the target file from the download task table of the preset database, then search for the index of each target fragment corresponding to the download task identifier from the fragment information table, and then obtain the maximum index from the found indexes.
[0105] Step 2: The ratio of the maximum index to the number of target shards included in the target file is used as the download progress of the target file.
[0106] The browser may use the number of sub-intervals obtained by dividing the file interval in S102 as the target number of fragments included in the target file.
[0107] The download progress may be in the form of a percentage. For example, if the maximum index is 3 and the number of target segments included in the target file is 5, the download progress of the target file is: 3 / 5=60%.
[0108] Optionally, the browser may execute step 1 and step 2 once every preset time interval and update the displayed download progress. Alternatively, the browser may execute step 1 and step 2 once every time a new target segment is stored in the preset database, and update the displayed download progress. This ensures the real-time nature of the download progress.
[0109] Through the above method, the browser can monitor the download progress in real time and dynamically update it by querying the index of the target segment stored in the preset database, thereby improving the transparency of the file download process, that is, visibility, so that users can understand the download progress more intuitively and enhance the download experience. Moreover, this method does not need to request the download progress from the server, thus effectively reducing the request frequency to the server and alleviating the network load. In addition, since the embodiment of the present disclosure adopts IndexedDB as the preset database of the browser, thanks to the large capacity and efficient reading and writing capabilities of IndexedDB, it is guaranteed that the browser can accurately record and save the downloaded segments and related information of the segments even in a complex network environment.
[0110] In addition to the above-mentioned method for implementing S103, the download progress of the target file may also be determined by other methods, which are not specifically limited in the embodiments of the present disclosure.
[0111] For example, the browser may calculate the sum of the fragment sizes of the target fragments stored in the preset database, and use the ratio of the sum to the file size of the target file as the download progress of the target file.
[0112] For another example, the browser may obtain the number of each target segment stored in a preset database, and use the ratio of the number to the number of target segments included in the target file as the download progress of the target file.
[0113] To enhance user experience, the browser may also display the download progress after determining the download progress of the target file in S103 above.
[0114] Wherein, the browser can display the download progress in the front-end progress bar module of the browser, wherein the front-end progress bar module can be implemented by modern Web technology, for example, by utilizing HyperText Markup Language 5 (HTML5), Cascading Style Sheets 3 (CSS3) and programming language (JavaScript) technology. The front-end progress bar module can dynamically display the download progress bar in a graphical manner, and update the download progress represented by the download progress bar in real time. The front-end progress bar module can also display the amount of data downloaded, the file size of the target file, the current download speed of the browser, and the estimated remaining download time, etc. Wherein, the browser can calculate the difference between the file size of the target file and the amount of data downloaded, and determine the remaining download time based on the difference and the current download speed.
[0115] Since the browser can display the download progress, users can intuitively view the download status of files, which improves the visibility of the file download process, ensures the user's understanding of the file download process, and improves the user's download experience when downloading files through the browser.
[0116] See also Figure 3 After all target segments of the target file are stored in the preset database, the browser can also reorganize the target segments, including the following steps:
[0117] S301. After all target fragments included in the target file are stored in a preset database, the target fragments are combined into a binary large object.
[0118] Optionally, the browser may obtain the maximum index among the indexes of each target shard stored in the preset database, and when the maximum index is equal to the number of target shards included in the target file, it is determined that each target shard included in the target file is stored in the preset database. Alternatively, the browser may obtain the number of target shards stored in the preset database, and when the number of target shards is equal to the number of target shards included in the target file, it is determined that each target shard included in the target file is stored in the preset database. Alternatively, the browser may calculate the sum of the shard sizes of the target shards stored in the preset database, and when the sum is equal to the file size of the target file, it is determined that each target shard included in the target file is stored in the preset database.
[0119] The browser may combine the target fragments into a Blob object by using the Binary Large Object (Blob) technology according to the indexes of the target fragments in ascending order.
[0120] S302: Generate a download link for the binary large object.
[0121] The browser can use the URL.createObjectURL() method to generate an accessible Uniform Resource Location (URL) based on the Blob object. The URL.createObjectURL() method is a method for generating a URL pointing to a specified web resource. In the embodiment of the present disclosure, the specified web resource is a Blob object.
[0122] S303: When it is detected that the download link is triggered, the binary large object is saved to a preset storage location of the terminal where the browser is located.
[0123] The download link may be triggered automatically, or the browser may display the download link and determine that the download link is triggered when detecting that the user clicks on the download link.
[0124] For example, the browser can create a temporary The HTML element of the tag, the hypertext reference (href) attribute of the HTML element is set to the download link generated in S302, and the download attribute of the HTML element is set to the file name of the target file, wherein the file name can be the original file name of the target file, or a file name set by the user. Afterwards, the browser can automatically save the binary large object to the preset storage location of the terminal where the browser is located by automatically executing the click event of the HTML element.
[0125] Optionally, the preset storage location may be a default storage location in the terminal for storing downloaded files, or the preset storage location may be a location selected by a user.
[0126] Through the above method, the browser can reorganize each target segment and save it to the preset storage location of the terminal, so that all types of files, such as documents, pictures, videos, and audios, can be quickly downloaded to the terminal, that is, seamless download and storage are achieved. The data reorganization and saving process is completely performed by the browser, and the browser does not need to interact with the server during the process, which reduces the burden on the server and protects the privacy of the terminal information.
[0127] In some embodiments of the present disclosure, the browser also supports breakpoint resumption, and the implementation method includes: if an interruption occurs in the process of downloading each target fragment from the first server respectively, and a continue downloading instruction is received, the maximum index in the index of the target fragment stored in the preset database is obtained, and then the target fragment after the target fragment corresponding to the maximum index is downloaded from the first server.
[0128] The interruption can be either passive or active. For example, when the network of the terminal where the browser is located is unstable or the network connection is disconnected, or the terminal is down, the browser is passively interrupted in downloading each target segment. For another example, when the browser detects that the user clicks the pause download button during the download of each target segment, the download process is actively interrupted, that is, the browser actively pauses the download.
[0129] The continue download instruction may be triggered automatically or by the user. For example, when the terminal network connection where the browser is located is restored, the continue download instruction may be automatically triggered. For another example, when it is detected that the user clicks the continue download button, the continue download instruction is determined to be triggered.
[0130] Since the browser can record the accurate data of the download process in real time in the preset database, when resuming the download, the browser can obtain the maximum index of each target fragment stored in the preset database, and the target fragment after the target fragment corresponding to the maximum index is the fragment that needs to be continued to be downloaded. After that, the browser can determine the sub-interval corresponding to the target fragment to which the maximum index belongs, generate a fragment download request for each sub-interval after the sub-interval, send it to the first server, and then obtain the target fragment from the fragment download response sent by the first server.
[0131] Through the above method, the browser can accurately locate the part of the target file that has been downloaded before the download is interrupted, and continue to download the remaining part without having to download the target file again from the beginning, that is, breakpoint resume is achieved. This method effectively reduces the amount of data that continues to be downloaded after the file download is interrupted, and improves the speed of obtaining the target file.
[0132] In the disclosed embodiment, the preset database also includes the download status of the target file. On this basis, the browser can also clean up the preset database, and the data cleaning method can be implemented as follows: from the preset database, determine the files to be cleaned whose download status is completed, and then delete the files to be cleaned, the fragments included in the files to be cleaned, and the download status corresponding to the files to be cleaned from the preset database.
[0133] The browser may execute the above-mentioned data cleaning method after storing the target file to the preset storage location of the terminal in the above-mentioned S303, or execute the above-mentioned data cleaning method periodically, or execute the above-mentioned data cleaning method when it detects that the amount of data stored in the preset database reaches the preset data amount. The embodiment of the present disclosure does not make any specific limitation on this.
[0134] The period for executing the above data cleaning method can be set according to actual needs, for example, the period is 7 days.
[0135] When performing data cleaning, the browser can determine the files to be cleaned up with a download status of completed download and the download task identifiers corresponding to the files to be cleaned up from the download task table. Then, the browser can find the shards, shard metadata, shard download status, storage keys, etc. corresponding to the download task identifiers from the shard information table. The browser can delete the data corresponding to the download task identifiers from the download task table and the shard information table.
[0136] Since the file is saved to the preset storage location of the terminal after downloading, the relevant information of the downloaded file can be deleted, reducing the occupation of useless data in the preset database, freeing up storage space, improving the utilization rate of storage resources, ensuring the efficient operation of the browser, and reducing the impact of invalid data on the load of storage resources.
[0137] See also Figure 4 The following introduces the various functional modules used by the browser in the downloading process of the target file in the embodiment of the present disclosure.
[0138] First, the browser requests the second server to identify whether the browser has the authority to download the target file by requesting the authentication module. After the authentication is passed, the browser obtains the metadata of the target file from the first server through the metadata request module, including the file size of the target file. Then the browser splits the file interval consisting of 0 and the file size into multiple sub-intervals through the data slicing module. Then the browser downloads the target slices corresponding to each sub-interval in the target file from the first server respectively through the continuous integration module, and stores the downloaded target slices in IndexedDB through the storage module. After the browser stores all the target slices included in the target file in IndexedDB, it combines the downloaded target slices through the file reorganization module, and stores the combined target file in the preset storage location of the terminal where the browser is located through the resource storage service. The browser can also delete the relevant information such as the slices and metadata included in the downloaded file from IndexedDB through the data cleaning module.
[0139] See also Figure 5 , the following is a detailed description of the process of browser downloading files based on actual application scenarios:
[0140] When the browser detects that the user initiates a download instruction for the target file, it sends an authentication request to the second server and receives an authentication response sent by the second server. If the authentication response indicates that the authentication fails, the browser does not download the file, and the download process ends. If the authentication response indicates that the authentication passes, the browser obtains the metadata of the target file from the first server. Then, the browser splits the file interval into multiple sub-intervals, generates a segment download task, downloads the target segment corresponding to the sub-interval from the first server in parallel, and stores the downloaded target segment in IndexedDB. At the same time, the browser asynchronously monitors the target segment stored in the preset database, and determines and displays the download progress of the target file according to the target segment stored in IndexedDB. The browser can also provide a breakpoint resume function according to the target segment stored in IndexedDB. After all the target segments included in the target file are stored in IndexedDB, the browser reorganizes the downloaded target segments and saves the reorganized target file to the preset storage location of the terminal where the browser is located. Afterwards, the browser checks whether there is a file to be cleaned up with a download status of completed in the preset database. If so, the file to be cleaned up, the fragments included in the file to be cleaned up, and the download status corresponding to the file to be cleaned up are deleted from IndexedDB. If not, the data currently stored in IndexedDB is retained.
[0141] It can be seen that the browser in the disclosed embodiment can perform fine-grained control over the download process when downloading files, so that the download strategy can be adjusted according to actual needs to optimize download efficiency and stability. In addition, the browser can also monitor the download progress throughout the process, and record and embed each link of the file download in detail, which not only provides empirical evidence for subsequent performance optimization such as breakpoint resumption, but also makes download problems traceable and analyzable. This method greatly enhances the user experience of file downloading through the browser, and at the same time lays the foundation for providing more personalized and efficient download services, and provides more possibilities for value-added services for commercial data transmission. The potential of this visual download method is not only reflected in enhancing individual user experience, but also in that it opens up a new optimization path for web application services, so that the design and implementation of the download function can be more closely combined with user needs and the complexity of the modern network environment, showing the broad development space of browser download in future network applications.
[0142] In the technical solution disclosed herein, the collection, storage, use, processing, transmission, provision and disclosure of the file information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0143] Based on the same inventive concept, the embodiment of the present disclosure also provides a device for downloading files through a browser, which is applied to the browser, such as Figure 6 As shown, the device includes: a receiving module 601, a splitting module 602 and a downloading module 603;
[0144] The receiving module 601 is used to receive a file download instruction, where the file download instruction is used to instruct to download a target file;
[0145] A splitting module 602 is used to obtain the file size of the target file, determine the file interval of the target file according to the file size, and split the file interval into multiple sub-intervals, wherein the maximum value of the file interval is the file size;
[0146] The download module 603 is used to download the target segments corresponding to each sub-interval in the target file from the first server respectively, store the downloaded target segments in the preset database of the browser, and asynchronously monitor the target segments stored in the preset database, and determine the download progress of the target file according to the target segments stored in the preset database.
[0147] In some embodiments of the present disclosure, the device further comprises:
[0148] A combining module, used for combining the target fragments included in the target file into a binary large object after all the target fragments are stored in a preset database;
[0149] A generation module, used to generate a download link for a binary large object;
[0150] The storage module is used to save the binary large object to a preset storage location of the terminal where the browser is located when it is detected that the download link is triggered.
[0151] In some embodiments of the present disclosure, the download module 603 is specifically used to:
[0152] For each sub-interval, a segment download request is sent to the first server, where the segment download request is used to request downloading of a target segment corresponding to the sub-interval in the target file;
[0153] A segment download response sent by the first server is received, and a target segment corresponding to the sub-interval is extracted from the segment download response.
[0154] In some embodiments of the present disclosure, the segment download response further includes an index of the target segment, and the index is used to indicate the position of the target segment in the target file; the download module 603 is specifically used to:
[0155] The target segments and indexes included in the segment download response are stored in a preset database accordingly.
[0156] In some embodiments of the present disclosure, the download module 603 is specifically used to:
[0157] Get the maximum index among the indexes of the target shard stored in the preset database;
[0158] The ratio of the maximum index to the number of target shards included in the target file is used as the download progress of the target file.
[0159] In some embodiments of the present disclosure, the device further comprises:
[0160] An acquisition module, configured to acquire the maximum index of the indexes of the target slices stored in the preset database if an interruption occurs in the process of downloading the target slices from the first server and a download continuation instruction is received;
[0161] The download module 603 is further configured to download, from the first server, the target fragment following the target fragment corresponding to the maximum index.
[0162] In some embodiments of the present disclosure, the preset database also includes the download status of the target file; the device also includes:
[0163] A determination module, used to determine the files to be cleaned up whose download status is completed from a preset database;
[0164] The deletion module is used to delete the to-be-cleaned file, each fragment included in the to-be-cleaned file, and the download status corresponding to the to-be-cleaned file from the preset database.
[0165] In some embodiments of the present disclosure, the splitting module 602 is specifically used to:
[0166] Sending a metadata acquisition request to the first server, where the metadata acquisition request is used to request to acquire metadata of the target file;
[0167] A metadata acquisition response sent by the first server is received, and a file size of the target file is extracted from the metadata of the target file included in the metadata acquisition response.
[0168] In some embodiments of the present disclosure, the device further comprises:
[0169] A sending module, used for sending an authentication request to the second server before sending a metadata acquisition request to the first server, wherein the authentication request is used for requesting the second server to identify whether the browser has the authority to download the target file;
[0170] The receiving module is further used to receive the authentication response sent by the second server;
[0171] The splitting module 602 is specifically used for:
[0172] If the authentication response indicates that the browser has the authority to download the target file, a metadata acquisition request is sent to the first server.
[0173] In some embodiments of the present disclosure, the splitting module 602 is specifically used to:
[0174] Get the preset shard size;
[0175] In the file interval, multiple sub-intervals are sequentially intercepted according to a preset fragmentation size starting from the minimum value of the file interval, wherein there is no intersection between the sub-intervals, and the union of the sub-intervals is the file interval.
[0176] In some embodiments of the present disclosure, the device further comprises:
[0177] The merging module is used to merge the second to last sub-interval and the last sub-interval if the interval size of the last sub-interval is smaller than the preset minimum interval size.
[0178] In some embodiments of the present disclosure, the splitting module 602 is specifically used to:
[0179] Get the preset number of shards;
[0180] The file interval is divided into a preset number of fragmentation sub-intervals, wherein there is no intersection between the sub-intervals, and the union of the sub-intervals is the file interval.
[0181] In some embodiments of the present disclosure, the device further comprises:
[0182] The display module is used to display the download progress after determining the download progress of the target file.
[0183] In some embodiments of the present disclosure, the minimum value of the file interval is 0.
[0184] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0185] Figure 7 A schematic block diagram of an example electronic device 700 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0186] like Figure 7As shown, the electronic device 700 includes a computing unit 701, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 702 or a computer program loaded from a storage unit 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the electronic device 700 can also be stored. The computing unit 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0187] Multiple components in the electronic device 700 are connected to the I / O interface 705, including: an input unit 706, such as a keyboard, a mouse, etc.; an output unit 707, such as various types of displays, speakers, etc.; a storage unit 708, such as a disk, an optical disk, etc.; and a communication unit 709, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 709 allows the electronic device 700 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0188] The computing unit 701 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 701 performs the various methods and processes described above, such as a method for downloading files through a browser. For example, in some embodiments, the method for downloading files through a browser may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 700 via ROM 702 and / or communication unit 709. When the computer program is loaded into RAM 703 and executed by the computing unit 701, one or more steps of the method for downloading files through a browser described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to execute a method for downloading files through a browser in any other appropriate manner (e.g., by means of firmware).
[0189] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0190] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0191] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0192] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0193] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0194] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0195] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0196] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A method for downloading a file through a browser, applied to the browser, comprising: Receiving a file download instruction, wherein the file download instruction is used to instruct to download a target file; Obtaining the file size of the target file, determining the file interval of the target file according to the file size, and splitting the file interval into multiple sub-intervals, wherein the maximum value of the file interval is the file size; The target segments corresponding to each subinterval in the target file are downloaded from the first server respectively, the downloaded target segments are stored in a preset database of the browser, and the target segments stored in the preset database are asynchronously monitored, and the download progress of the target file is determined according to the target segments stored in the preset database.
2. The method according to claim 1, further comprising: After all target fragments included in the target file are stored in the preset database, combining the target fragments into a binary large object; Generating a download link for the binary large object; When it is detected that the download link is triggered, the binary large object is saved to a preset storage location of the terminal where the browser is located.
3. The method according to claim 1, wherein: The downloading of target segments corresponding to each sub-interval in the target file from the first server respectively includes: For each sub-interval, sending a fragment download request to the first server, wherein the fragment download request is used to request downloading of a target fragment corresponding to the sub-interval in the target file; Receive a segment download response sent by the first server, and extract a target segment corresponding to the sub-interval from the segment download response.
4. The method according to claim 3, wherein: The segment download response further includes an index of the target segment, where the index is used to indicate a position of the target segment in the target file; and storing the downloaded target segment in a preset database of the browser includes: The target segments and indexes included in the segment download response are stored in the preset database accordingly.
5. The method according to claim 4, wherein: The step of determining the download progress of the target file according to the target slice stored in the preset database includes: Obtain the maximum index among the indexes of the target shard stored in the preset database; The ratio of the maximum index to the number of target fragments included in the target file is used as the download progress of the target file.
6. The method according to claim 4, further comprising: If an interruption occurs during the process of downloading each target segment from the first server, and a download continuation instruction is received, obtaining the maximum index among the indexes of the target segments stored in the preset database; Download the target slice following the target slice corresponding to the maximum index from the first server.
7. The method according to claim 4, wherein the preset database further includes the download status of the target file; the method further includes: Determine from the preset database the files to be cleaned up whose download status is completed; The to-be-cleaned file, each fragment included in the to-be-cleaned file, and the download status corresponding to the to-be-cleaned file are deleted from the preset database.
8. The method according to claim 1, wherein: The obtaining the file size of the target file comprises: Sending a metadata acquisition request to the first server, where the metadata acquisition request is used to request to acquire metadata of the target file; A metadata acquisition response sent by the first server is received, and a file size of the target file is extracted from the metadata of the target file included in the metadata acquisition response.
9. The method according to claim 8, before sending the metadata acquisition request to the first server, further comprising: Sending an authentication request to the second server, wherein the authentication request is used to request the second server to identify whether the browser has the authority to download the target file; receiving an authentication response sent by the second server; The step of sending a metadata acquisition request to the first server includes: If the authentication response indicates that the browser has the authority to download the target file, a metadata acquisition request is sent to the first server.
10. The method according to claim 1, wherein: The step of splitting the file interval into a plurality of sub-intervals comprises: Get the preset shard size; In the file interval, multiple sub-intervals are sequentially intercepted according to the preset fragment size starting from the minimum value of the file interval, wherein there is no intersection between the sub-intervals, and the union of the sub-intervals is the file interval.
11. The method according to claim 10, after sequentially intercepting a plurality of sub-intervals from the minimum value of the file interval according to the preset fragment size in the file interval, further comprising: If the interval size of the last subinterval is smaller than the preset minimum interval size, the second to last subinterval and the last subinterval are merged.
12. The method according to claim 1, wherein: The step of splitting the file interval into a plurality of sub-intervals comprises: Get the preset number of shards; The file interval is divided into sub-intervals of the preset number of fragments, wherein there is no intersection between the sub-intervals, and the union of the sub-intervals is the file interval.
13. The method according to any one of claims 1 to 12, after determining the download progress of the target file, further comprising: The progress of the download is displayed.
14. The method according to any one of claims 1 to 12, wherein: The minimum value of the file interval is 0.
15. A device for downloading files through a browser, applied to the browser, comprising: A receiving module, used for receiving a file download instruction, wherein the file download instruction is used for instructing to download a target file; A splitting module, used for obtaining the file size of the target file, determining the file interval of the target file according to the file size, and splitting the file interval into a plurality of sub-intervals, wherein the maximum value of the file interval is the file size; A download module is used to download the target segments corresponding to each sub-interval in the target file from the first server respectively, store the downloaded target segments in the preset database of the browser, and asynchronously monitor the target segments stored in the preset database, and determine the download progress of the target file according to the target segments stored in the preset database.
16. The apparatus according to claim 15, further comprising: A combining module, configured to combine the target fragments included in the target file into a binary large object after all the target fragments are stored in the preset database; A generation module, used for generating a download link of the binary large object; The storage module is used to save the binary large object to a preset storage location of the terminal where the browser is located when it is detected that the download link is triggered.
17. The device according to claim 15, wherein: The download module is specifically used for: For each sub-interval, sending a fragment download request to the first server, wherein the fragment download request is used to request downloading of a target fragment corresponding to the sub-interval in the target file; Receive a segment download response sent by the first server, and extract a target segment corresponding to the sub-interval from the segment download response.
18. The device according to claim 17, wherein: The segment download response further includes an index of the target segment, where the index is used to indicate the position of the target segment in the target file; the download module is specifically used to: The target segments and indexes included in the segment download response are stored in the preset database accordingly.
19. The device according to claim 18, wherein The download module is specifically used for: Obtain the maximum index among the indexes of the target shard stored in the preset database; The ratio of the maximum index to the number of target fragments included in the target file is used as the download progress of the target file.
20. The apparatus of claim 18, further comprising: an acquisition module, configured to acquire the maximum index of the indexes of the target slices stored in the preset database if an interruption occurs in the process of downloading the target slices from the first server and a download continuation instruction is received; The download module is further used to download, from the first server, the target slice following the target slice corresponding to the maximum index.
21. The device according to claim 18, wherein the preset database further includes a download status of the target file; the device further includes: A determination module, used to determine the files to be cleaned up whose download status is completed from the preset database; The deleting module is used to delete the to-be-cleaned file, each fragment included in the to-be-cleaned file, and the download status corresponding to the to-be-cleaned file from the preset database.
22. The device according to claim 15, wherein: The splitting module is specifically used for: Sending a metadata acquisition request to the first server, where the metadata acquisition request is used to request to acquire metadata of the target file; A metadata acquisition response sent by the first server is received, and a file size of the target file is extracted from the metadata of the target file included in the metadata acquisition response.
23. The apparatus according to claim 22, further comprising: A sending module, used for sending an authentication request to a second server before sending the metadata acquisition request to the first server, wherein the authentication request is used for requesting the second server to identify whether the browser has the authority to download the target file; The receiving module is further used to receive an authentication response sent by the second server; Wherein, the splitting module is specifically used for: If the authentication response indicates that the browser has the authority to download the target file, a metadata acquisition request is sent to the first server.
24. The device according to claim 15, wherein: The splitting module is specifically used for: Get the preset shard size; In the file interval, multiple sub-intervals are sequentially intercepted according to the preset fragment size starting from the minimum value of the file interval, wherein there is no intersection between the sub-intervals, and the union of the sub-intervals is the file interval.
25. The apparatus according to claim 24, further comprising: The merging module is configured to merge the second to last sub-interval and the last sub-interval if the interval size of the last sub-interval is smaller than a preset minimum interval size.
26. The device according to claim 15, wherein: The splitting module is specifically used for: Get the preset number of shards; The file interval is divided into sub-intervals of the preset number of fragments, wherein there is no intersection between the sub-intervals, and the union of the sub-intervals is the file interval.
27. The apparatus according to any one of claims 15 to 26, further comprising: The display module is used to display the download progress after the download progress of the target file is determined.
28. The device according to any one of claims 15 to 26, wherein: The minimum value of the file interval is 0.
29. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 14.
30. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-14.
31. A computer program product comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 14.
Citation Information
Patent Citations
Progress bar implementation method and device
CN109558129A
File fragment downloading method and device
CN111586103A
File downloading method and device, server and storage medium
CN113411404A
File downloading method and device, electronic equipment and computer storage medium
CN114513503A
Streaming-based method for realizing fragmented downloading of large file of browser
CN118041929A
Cited By
Data downloading method and device, storage medium and electronic equipment
CN119135677A
File transmission method and device, electronic equipment and storage medium
CN119363734A
