File streaming downloading method, system, equipment and program product
File streaming download is achieved through front-end Fetch-API and ZIP instances, which solves the problems of high memory usage and loading delay when downloading large files, improves download efficiency and user experience, reduces system resource usage, and supports large files and batch files. download.
Patent Information
- Application Number
- CN202411477577.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-22
- Publication Date
- 2024-12-03
AI Technical Summary
When processing large files, existing file download methods will lead to high memory usage and long loading delays, affecting system performance, and cannot be downloaded directly to the local area but open directly in the browser, affecting the user experience.
Send download requests to the file server through the Fetch-API of the front-end, download the file to the writable stream created by the front-end, and use the ZIP instance to compress the file in real time and store it on the hard disk. StreamSaver.js and zip-stream are used to implement streaming Download style.
It significantly reduces memory usage, reduces the use of system resources, improves download efficiency, and supports the download of large files and batch files, avoids request timeout issues, and ensures the integrity and user experience of downloaded files.
Smart Images

Figure CN119071289A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of streaming transmission technology, and in particular to a file streaming downloading method, system, equipment and program product. Background Art
[0002] In the existing traditional file download method, the browser usually uses memory caching and hard disk writing to handle file downloads. When a user clicks a download link, the browser will first download the file into the memory and then write it to the specified location on the hard disk. This method can ensure the integrity and security of file downloads, but for large files, this method will result in significant memory usage and long loading delays, especially when memory resources are limited, which may affect the performance of other applications.
[0003] Existing file download methods may cause inconvenience to users. Several aspects that affect user experience include: 1. Memory usage issues: Especially when processing large files, the browser may occupy a large amount of memory, resulting in reduced system performance or restricted operation of other programs. 2. Loading delay: Large files take longer to download and process, and users may have to wait for a long time before they can access or use the files. 3. Direct display of files: Sometimes users want to download files locally instead of opening them directly in the browser, so directly displaying files may lead to misunderstandings or may not meet user expectations.
[0004] Therefore, it is urgent to invent a file streaming download method to solve the download performance problem caused by the excessive size of the file, improve the download efficiency, and reduce the occupation of system resources. Summary of the invention
[0005] In view of this, embodiments of the present invention provide a file streaming download method, system, device and program product, which at least partially solve the problems existing in the prior art.
[0006] Other features and advantages of the present invention will become apparent from the following detailed description, or may be learned in part by practice of the present invention.
[0007] In order to achieve the above purpose, the embodiment of the present invention provides the following technical solutions:
[0008] According to a first aspect of an embodiment of the present invention, a method for streaming downloading a file is provided, the method comprising:
[0009] Send the user download request to the file server through the front-end Fetch-API, and according to the file path of the file to be downloaded returned, stream the file to be downloaded in the file server to the writable stream created by the front-end;
[0010] Use the front-end ZIP instance to compress the files in the writable stream and store them on the user's hard disk in real time.
[0011] Furthermore, according to the file path of the file to be downloaded returned, the file to be downloaded in the file server is streamed to the writable stream created by the front end, and the file in the writable stream is compressed by the ZIP instance of the front end and stored in the user's hard disk in real time, including:
[0012] Use the createWriteStream method of StreamSaver.js to create a writable stream corresponding to the file to be downloaded on the front end;
[0013] According to the file path corresponding to the file to be downloaded, the URL corresponding to the file to be downloaded is accessed by using the fectch method, and the file to be downloaded is streamed and downloaded to the writable stream;
[0014] For the file to be downloaded, create a corresponding ZIP instance using zip-stream on the front end;
[0015] Utilizing the ZIP instance to continuously receive the downloaded files in the writable stream and storing the data in the ZIP instance on the user's hard disk;
[0016] When all the data of the file to be downloaded is downloaded, the close method is executed to package the ZIP instance into a compressed package.
[0017] According to a second aspect of an embodiment of the present invention, a file downloading method is provided, the method comprising:
[0018] Send user download requests to the file server through the front end;
[0019] If the download request is a download request sent through the Fetch-API of the front end, then obtain the file information to be downloaded;
[0020] Based on the information of the file to be downloaded, obtaining a file path corresponding to the file to be downloaded;
[0021] According to the file path, streaming download the file to be downloaded in the file server to the writable stream created by the front end;
[0022] Use the front-end ZIP instance to compress the files in the writable stream and store them on the user's hard disk in real time.
[0023] Furthermore, the method further comprises:
[0024] If the download request is not a download request sent through the Fetch-API of the front end, the file to be downloaded is directly downloaded at the back end.
[0025] Further, based on the information of the file to be downloaded, obtaining a file path corresponding to the file to be downloaded includes:
[0026] According to the information of the file to be downloaded, determining whether the size of the file to be downloaded is greater than a preset file size threshold;
[0027] If the size of the file to be downloaded is greater than a preset file size threshold, guiding the PC client to download the file to be downloaded;
[0028] If the size of the file to be downloaded is less than or equal to a preset file size threshold, obtaining a first path corresponding to the file to be downloaded;
[0029] Perform path decryption processing on the first path to obtain a decrypted second path.
[0030] Further, according to the file path, streaming the file to be downloaded in the file server to the writable stream created by the front end, compressing the file in the writable stream by using the ZIP instance of the front end and storing it in real time on the user's hard disk includes:
[0031] Use the createWriteStream method of StreamSaver.js to create a writable stream corresponding to the file to be downloaded on the front end;
[0032] According to the file path corresponding to the file to be downloaded, the URL corresponding to the file to be downloaded is accessed by using the fectch method, and the file to be downloaded is streamed and downloaded to the writable stream;
[0033] For the file to be downloaded, create a corresponding ZIP instance using zip-stream on the front end;
[0034] Utilizing the ZIP instance to continuously receive the downloaded files in the writable stream and storing the data in the ZIP instance on the user's hard disk;
[0035] When all the data of the file to be downloaded is downloaded, the close method is executed to package the ZIP instance into a compressed package.
[0036] According to a third aspect of an embodiment of the present invention, a file streaming downloading system is provided, the system comprising:
[0037] The request sending module is used to send user download requests to the file server through the front-end Fetch-API;
[0038] The streaming download module is used to stream the files to be downloaded from the file server to the writable stream created by the front end according to the file path of the files to be downloaded returned;
[0039] The compression storage module is used to compress the files in the writable stream using the front-end ZIP instance and store them in real time on the user's hard disk.
[0040] According to a fourth aspect of an embodiment of the present invention, a file downloading system is provided, the system comprising:
[0041] A download request sending module is used to send a download request to a file server through a front end;
[0042] A file information acquisition module, used for acquiring information of the file to be downloaded if the download request is a download request sent by the user through the Fetch-API of the front end;
[0043] A file path acquisition module, used to acquire the file path corresponding to the file to be downloaded based on the file information to be downloaded;
[0044] A streaming download module, used for streaming downloading the file to be downloaded in the file server to the writable stream created by the front end according to the file path;
[0045] The compression storage module is used to compress the files in the writable stream using the front-end ZIP instance and store them in real time on the user's hard disk.
[0046] According to a fifth aspect of an embodiment of the present invention, there is provided a file downloading device, the device comprising: a processor and a memory;
[0047] The memory is used to store one or more program instructions;
[0048] The processor is used to run one or more program instructions to execute the steps of a file streaming downloading method or a file downloading method as described in any one of the above items.
[0049] According to a fourth aspect of an embodiment of the present invention, a computer program product is provided, the computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions, which, when executed by a computer, enable the computer to implement a file streaming downloading method or steps of a file downloading method as described in any one of the above items.
[0050] The embodiments of the present invention have the following advantages:
[0051] The embodiment of the present invention provides a method, system, device and program product for file streaming downloading, the method comprising: sending a user download request to a file server through a front-end Fetch-API, streaming downloading the file to be downloaded in the file server to a writable stream created by the front-end according to the file path of the file to be downloaded returned; using the front-end ZIP instance to compress the file in the writable stream and store it in real time on the user's hard disk. The present invention can solve the download performance problem caused by the file being too large, improve the download efficiency, and reduce the occupation of system resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the implementation methods of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for the implementation methods or the description of the prior art. Obviously, the drawings in the following description are only exemplary, and for ordinary technicians in this field, other implementation drawings can be derived from the provided drawings without creative work.
[0053] Figure 1 A flowchart of a file downloading method provided by an embodiment of the present invention;
[0054] Figure 2 A schematic diagram of the structure of a file downloading system provided by an embodiment of the present invention;
[0055] Figure 3 A schematic block diagram of the principles of a file downloading method provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0056] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below 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 of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0057] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof 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 that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0058] In order to solve the defects of the prior art, the present invention provides a file streaming download method, which comprises: firstly, sending a user download request to a file server through a front-end Fetch-API, and streaming the file to be downloaded in the file server to a writable stream created by a front-end according to the file path of the file to be downloaded returned; and then using a ZIP instance of the front-end to compress the file in the writable stream and store it in real time on the user's hard disk.
[0059] The above steps specifically include: after the user clicks the download link, the user download request is sent to the file server through the front-end Fetch-API. After the front-end receives the download task identifier returned by the file server, the createWriteStream method of StreamSaver.js is used to create a writable stream corresponding to the file to be downloaded on the front-end; according to the file path corresponding to the file to be downloaded, the fectch method is used to access the URL corresponding to the file to be downloaded, and the file to be downloaded is streamed to the writable stream; for the file to be downloaded, the corresponding ZIP instance is created on the front-end using zip-stream; the ZIP instance is used to continuously receive the files downloaded from the writable stream and the data in the ZIP instance is stored in the user's hard disk in real time; after all the data of the file to be downloaded is downloaded, the close method is executed to package the ZIP instance into a compressed package.
[0060] In addition, an embodiment of the present invention further provides a file streaming download system, the system specifically comprising:
[0061] The request sending module is used to send user download requests to the file server through the front-end Fetch-API;
[0062] The streaming download module is used to stream the files to be downloaded from the file server to the writable stream created by the front end according to the file path of the files to be downloaded returned;
[0063] The compression storage module is used to compress the files in the writable stream using the front-end ZIP instance and store them in real time on the user's hard disk.
[0064] In addition, the embodiment of the present invention also provides a file downloading method. Figure 1 The figure shows a flow chart of a file downloading method according to an embodiment of the present invention.
[0065] like Figure 1 and Figure 3 As shown, a file downloading method according to an embodiment of the present invention may include step S100, step S200, step S300, step S400 and step S500.
[0066] In step S100, a user download request is sent to a file server via the front end.
[0067] Specifically, the above steps include:
[0068] After the user clicks the download link, the user download request is sent to the file server through the front-end Fetch-API.
[0069] Next, in step S200, if the download request is a download request sent through the Fetch-API of the front end, the information of the file to be downloaded is obtained.
[0070] Specifically, the above steps include:
[0071] Determine whether the download request sent by the front end is a download request sent through the Fetch-API of the front end; if the download request is a download request sent through the Fetch-API of the front end, obtain the file information to be downloaded; if the download request is not a download request sent through the Fetch-API of the front end, directly package and download the file to be downloaded on the back end.
[0072] In step S300, based on the information of the file to be downloaded, the file path corresponding to the file to be downloaded is obtained.
[0073] Specifically, the above steps include:
[0074] According to the information of the file to be downloaded, determine whether the size of the file to be downloaded is greater than the preset file size threshold; if the size of the file to be downloaded is greater than the preset file size threshold (for example, the preset file size threshold is 2G), guide the PC client to download the file to be downloaded; if the size of the file to be downloaded is less than or equal to the preset file size threshold, obtain the AES encrypted first path corresponding to the file to be downloaded; perform AES decryption processing on the first path to obtain the decrypted second path.
[0075] Next, in step S400, the file to be downloaded in the file server is streamed and downloaded to the writable stream created by the front end according to the file path.
[0076] Specifically, the above steps include:
[0077] After the front end receives the download task identifier returned by the server, the createWriteStream method of StreamSaver.js is used to create a writable stream streamSaver.createWriteStream ('file name.suffix') corresponding to the file to be downloaded on the front end. The writable stream supports write operations.
[0078] Then, according to the file path corresponding to the file to be downloaded, the fectch method is used to access the URL corresponding to the file to be downloaded, and the file to be downloaded is streamed and downloaded to the above-mentioned writable stream.
[0079] Finally, in step S500, the files in the writable stream are compressed using the front-end ZIP instance and stored in the user's hard disk in real time.
[0080] Specifically, the above steps include:
[0081] For the file to be downloaded, the corresponding ZIP instance is created on the front end using zip-stream; the ZIP instance is used to continuously receive the files downloaded from the writable stream and store the data in the ZIP instance in real time on the user's hard disk. After all the data of the downloaded file is downloaded, the close method is executed to package the ZIP instance into a compressed package.
[0082] In addition, the embodiment of the present invention also provides a file download system, referring to Figure 2 , the above system specifically includes:
[0083] A download request sending module is used to send a download request to a file server through a front end;
[0084] The file information acquisition module is used to acquire the information of the file to be downloaded if the download request is a download request sent by the user through the Fetch-API of the front end;
[0085] A file path acquisition module, used to acquire the file path corresponding to the file to be downloaded based on the file information to be downloaded;
[0086] The streaming download module is used to stream the files to be downloaded from the file server to the writable stream created by the front end according to the file path;
[0087] The compression storage module is used to compress the files in the writable stream using the front-end ZIP instance and store them in real time on the user's hard disk.
[0088] In addition, an embodiment of the present invention also provides a file downloading device, which includes: a processor and a memory; the memory is used to store one or more program instructions; the processor is used to run one or more program instructions to execute a file streaming downloading method or steps of a file downloading method as described above.
[0089] In addition, an embodiment of the present invention further provides a computer program product, which includes computer program instructions. When the computer program instructions are executed by a processor, the above-mentioned file streaming downloading method or steps of a file downloading method are implemented.
[0090] The file transfer link in the prior art is: from the file server to the application server, and then to the browser. This link transmission consumes a lot of time and server traffic, and because the file is packaged on the server, it consumes a lot of server performance. When downloading and packaging large files, there is a connection timeout problem.
[0091] The file transmission link of a file streaming download method, system, device and program product provided by the embodiment of the present invention is: directly from the file server to the browser. It can significantly shorten the transmission time, reduce the traffic and performance consumption of the server, and decompose a large request into multiple small requests, thereby avoiding the problem of request timeout, and can ensure that the downloaded file exceeds 10G without disconnecting the connection.
[0092] In summary, the embodiments of the present invention provide a method, system, device and program product for file streaming downloading, which downloads large files through the StreamSaver.js method and transmits them to the hard disk of the user device block by block during the download process, thereby significantly reducing memory usage and avoiding performance problems caused by excessively large files. At the same time, the present invention supports the function of batch downloading of large files, can process download requests for multiple large files, and download them in batches through streaming transmission, further improving download efficiency and reducing the occupation of system resources. The present invention can solve the download performance problem caused by excessively large files, improve download efficiency, and reduce the occupation of system resources.
[0093] In the embodiment of the present invention, the processor may be an integrated circuit chip with signal processing capability. The processor may be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gates or transistor logic devices, or discrete hardware components. The methods, steps, and logic block diagrams disclosed in the embodiments of the present invention may be implemented or executed. The general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present invention may be directly embodied as being executed by a hardware decoding processor, or may be executed by a combination of hardware and software modules in a decoding processor. The software module may be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The processor reads the information in the storage medium and completes the steps of the above method in combination with its hardware. The storage medium may be a memory, for example, a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM) and direct memory bus random access memory (Direct Rambus RAM, DRRAM).The storage medium described in the embodiment of the present invention is intended to include but is not limited to these and any other suitable types of memory. Those skilled in the art should be aware that in one or more of the above examples, the functions described in the present invention can be implemented by a combination of hardware and software. When the software is applied, the corresponding function can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein the communication medium includes any medium that is convenient for transmitting a computer program from one place to another. The storage medium can be any available medium that a general or special-purpose computer can access. Although the present invention has been described in detail above with general descriptions and specific embodiments, it is obvious to those skilled in the art that some modifications or improvements can be made to it on the basis of the present invention. Therefore, these modifications or improvements made on the basis of not departing from the spirit of the present invention all belong to the scope of protection claimed in the present invention.
Claims
1. A file streaming download method, It is characterized in that The method comprises: Send the user download request to the file server through the front-end Fetch-API, and according to the file path of the file to be downloaded returned, stream the file to be downloaded in the file server to the writable stream created by the front-end; Use the front-end ZIP instance to compress the files in the writable stream and store them on the user's hard disk in real time.
2. A file streaming download method as claimed in claim 1, It is characterized in that According to the file path of the file to be downloaded returned, the file to be downloaded in the file server is streamed to the writable stream created by the front end, and the file in the writable stream is compressed by the ZIP instance of the front end and stored in the user's hard disk in real time, including: Use the createWriteStream method of StreamSaver.js to create a writable stream corresponding to the file to be downloaded on the front end; According to the file path corresponding to the file to be downloaded, the URL corresponding to the file to be downloaded is accessed by using the fectch method, and the file to be downloaded is streamed and downloaded to the writable stream; For the file to be downloaded, create a corresponding ZIP instance using zip-stream on the front end; Utilizing the ZIP instance to continuously receive the downloaded files in the writable stream and storing the data in the ZIP instance on the user's hard disk; When all the data of the file to be downloaded is downloaded, the close method is executed to package the ZIP instance into a compressed package.
3. A file downloading method, It is characterized in that The method comprises: Send user download requests to the file server through the front end; If the download request is a download request sent through the Fetch-API of the front end, then obtain the file information to be downloaded; Based on the information of the file to be downloaded, obtaining a file path corresponding to the file to be downloaded; According to the file path, streaming download the file to be downloaded in the file server to the writable stream created by the front end; Use the front-end ZIP instance to compress the files in the writable stream and store them on the user's hard disk in real time.
4. A file downloading method as claimed in claim 3, It is characterized in that The method further comprises: If the download request is not a download request sent through the Fetch-API of the front end, the file to be downloaded is directly downloaded at the back end.
5. A file downloading method as claimed in claim 3, It is characterized in that Based on the information of the file to be downloaded, obtaining a file path corresponding to the file to be downloaded includes: According to the information of the file to be downloaded, determining whether the size of the file to be downloaded is greater than a preset file size threshold; If the size of the file to be downloaded is greater than a preset file size threshold, guiding the PC client to download the file to be downloaded; If the size of the file to be downloaded is less than or equal to a preset file size threshold, obtaining a first path corresponding to the file to be downloaded; Perform path decryption processing on the first path to obtain a decrypted second path.
6. A file downloading method as claimed in claim 3, It is characterized in that According to the file path, streaming the file to be downloaded in the file server to the writable stream created by the front end, and compressing the file in the writable stream by using the ZIP instance of the front end and storing it in real time on the user's hard disk include: Use the createWriteStream method of StreamSaver.js to create a writable stream corresponding to the file to be downloaded on the front end; According to the file path corresponding to the file to be downloaded, the URL corresponding to the file to be downloaded is accessed by using the fectch method, and the file to be downloaded is streamed and downloaded to the writable stream; For the file to be downloaded, create a corresponding ZIP instance using zip-stream on the front end; Utilizing the ZIP instance to continuously receive the downloaded files in the writable stream and storing the data in the ZIP instance on the user's hard disk; When all the data of the file to be downloaded is downloaded, the close method is executed to package the ZIP instance into a compressed package.
7. A file streaming download system, It is characterized in that The system comprises: The request sending module is used to send user download requests to the file server through the front-end Fetch-API; The streaming download module is used to stream the files to be downloaded from the file server to the writable stream created by the front end according to the file path of the files to be downloaded returned; The compression storage module is used to compress the files in the writable stream using the front-end ZIP instance and store them in real time on the user's hard disk.
8. A file downloading system, It is characterized in that The system comprises: A download request sending module is used to send a download request to a file server through a front end; A file information acquisition module, used for acquiring information of the file to be downloaded if the download request is a download request sent by the user through the Fetch-API of the front end; A file path acquisition module, used to acquire the file path corresponding to the file to be downloaded based on the file information to be downloaded; A streaming download module, used for streaming downloading the file to be downloaded in the file server to the writable stream created by the front end according to the file path; The compression storage module is used to compress the files in the writable stream using the front-end ZIP instance and store them in real time on the user's hard disk.
9. A file downloading device, It is characterized in that The device comprises: a processor and a memory; The memory is used to store one or more program instructions; The processor is used to run one or more program instructions to execute the steps of a file streaming downloading method as described in any one of claims 1 to 2 or a file downloading method as described in any one of claims 3 to 6.
10. A computer program product, It is characterized in that The computer program product comprises computer program instructions, which, when executed by a processor, implement the steps of a file streaming downloading method as claimed in any one of claims 1 to 2 or a file downloading method as claimed in any one of claims 3 to 6.
