File uploading method and device, equipment and storage medium

By dividing large files into first and second file slice sets, and calculating their hash values ​​to determine the file slice name, combined with an upload strategy that limits the number of concurrency, the problem of easy jamming of large files is solved, and more efficient file upload is achieved.

CN119946037APending Publication Date: 2025-05-06CHINA UNITED NETWORK COMM GRP CO LTD +2
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202311439779.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-11-01
Publication Date
2025-05-06

AI Technical Summary

Technical Problem

The existing large file upload method is prone to being stuck and has poor results.

Method used

By dividing the original file into the first file slice set by preset size, retaining the first and tail slices, generating the second file slice set, computing its hash value to determine the file slice name, and limiting the number of concurrency for uploading.

Benefits of technology

It shortens hash calculation time, reduces file upload time, reduces the risk of uploading stuck, and improves user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119946037A_ABST
    Figure CN119946037A_ABST
Patent Text Reader

Abstract

The invention provides a file uploading method and device, equipment and a storage medium. The method comprises the steps that a first file slice set is determined, the first file slice set comprises first file slices, and the slice size of the first file slices meets the preset slice size requirement; generating a second file slice set according to the first file slices at the target position and the first file slices at other positions in the first file slice set; determining a hash value of the second file slice set; determining the name of the first file slice according to the hash value of the second file slice set; obtaining a target first file slice set according to the name of the first file slice and the first file slice set; and sending the target first file slice set to a server, so that the server combines the first file slices according to the name of each first file slice in the target first file slice set to obtain a target file. And through the second file slice set, the time for calculating the hash value is shortened, and the file uploading speed is increased.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of file transmission technology, and in particular to a method, device, equipment and storage medium for uploading a file. Background Art

[0002] File uploading is a very common scenario, especially in some resource management related businesses, which involves the need to upload large files (i.e. files that occupy a large amount of memory), such as resource management businesses involving uploading videos and audios.

[0003] Currently, there are two main ways to upload large files: one is to directly send the file using post or form request; the other is to split the file into segments and upload it, splitting the large file into small files for uploading.

[0004] However, the existing method of uploading large files is prone to jamming and has poor performance. Summary of the invention

[0005] The present application provides a method, device, equipment and storage medium for uploading files, which are used to solve the problem that the existing method for uploading large files is prone to jamming and has poor effect.

[0006] In a first aspect, the present application provides a method for uploading a file, comprising:

[0007] Determine a first file slice set, the first file slice set includes a first file slice, and a slice size of the first file slice meets a preset slice size requirement;

[0008] Generate a second file slice set according to the first file slice at the target position and the first file slice at other positions in the first file slice set, wherein the second file slice set includes the target second file slice and other second file slices, the target second file slice corresponds to the first file slice at the target position, and the other second file slices are generated according to the target position bytes in the first file slice at other positions;

[0009] determining a hash value of a second set of file slices;

[0010] Determine the name of the first file slice according to the hash value of the second file slice set;

[0011] Obtaining a target first file slice set according to the name of the first file slice and the first file slice set;

[0012] The target first file slice set is sent to the server, so that the server merges the first file slices according to the names of the first file slices in the target first file slice set to obtain the target file.

[0013] In the present application, generating a second file slice set according to the first file slice at the target position and the first file slice at other positions in the first file slice set includes:

[0014] Determine a target position and other positions in the first file slice set, a first file slice at the target position, and a first file slice at other positions, wherein the target position is a head position and a tail position of the first file slice set;

[0015] Determine the first file slice in the first file slice set at the target position as the target second file slice;

[0016] Determine a target position byte in the first file slice at another position, wherein the target position byte is in the first file slice at another position;

[0017] Generate other second file slices according to the target position bytes in the first file slices at other positions;

[0018] A second file slice set is obtained according to the target second file slice and other second file slices.

[0019] In this application, determining the hash value of the second file slice set includes:

[0020] Get the execution priority of each task in the file upload system;

[0021] Determine the available time slices in the file upload system according to the execution priority of each task in the file upload system;

[0022] If the available time slices meet the preset time slice requirements, the available time slices are used to determine the hash value of the second file slice set.

[0023] Among them, in this application, after determining the available time slices in the file upload system according to the execution priority of each task in the file upload system, the method further includes:

[0024] If the available time slice does not meet the preset time slice requirement, the task whose execution priority meets the preset priority requirement is executed in the file upload system until the available time slice meets the preset time slice requirement, and then the available time slice is used to determine the hash value of the second file slice set.

[0025] Among them, in this application, determining the name of the first file slice according to the hash value of the second file slice set includes:

[0026] Determine a sorting identifier of each first file slice in the first file slice set;

[0027] Determine the name of the first file slice according to the sorting identifier of each first file slice in the first file slice set and the hash value of the second file slice set.

[0028] In this application, the target first file slice set is sent to the server, so that the server merges the first file slices according to the names of the first file slices in the target first file slice set to obtain the target file, including:

[0029] Determine the preset number of concurrent uploads in the file upload system;

[0030] According to the concurrency number preset in the file upload system, a first file slice upload request corresponding to the concurrency number is sent to the server, so that the server writes the name of the first file slice in the first file slice upload request into the uploaded slice name list in the server, wherein the first file slice upload request is generated according to the first file slice in the target first file slice set;

[0031] Determining, according to the first file slice upload request, an upload progress of a first file slice in a target first file slice set from an upload list;

[0032] If the upload progress indicates that the target first file slice set has been uploaded, all first file slice upload requests in the upload list are deleted, and the server merges the first file slices according to the names of the first file slices in the target first file slice set to obtain the target file.

[0033] Among them, in the present application, after sending a first file slice upload request corresponding to the concurrent number to the server according to the concurrent number preset in the file upload system, so that the server writes the name of the first file slice in the first file slice upload request into the uploaded slice name list in the server, the method also includes:

[0034] receiving target instructions;

[0035] Determine the status of the first file slice upload request according to the target instruction;

[0036] If the status of the first file slice upload request is upload interruption or upload pause, all first file slice upload requests in the file upload system are cleared.

[0037] Among them, in the present application, if the status of the first file slice upload request is upload interruption or upload suspension, after clearing all first file slice upload requests in the file upload system, the method further includes:

[0038] Get the list of uploaded slice names in the server;

[0039] According to the uploaded slice name list and the concurrent number, re-execute the step of sending the first file slice upload request corresponding to the concurrent number to the server, so that the server writes the name of the first file slice in the first file slice upload request into the uploaded slice name list in the server.

[0040] In a second aspect, the present application provides a file uploading device, comprising:

[0041] A first determining module is used to determine a first file slice set, where the first file slice set includes a first file slice, and a slice size of the first file slice meets a preset slice size requirement;

[0042] A generating module, used for generating a second file slice set according to the first file slice at the target position and the first file slice at other positions in the first file slice set, wherein the second file slice set includes the target second file slice and other second file slices, the target second file slice corresponds to the first file slice at the target position, and the other second file slices are generated according to the target position bytes in the first file slice at other positions;

[0043] A second determination module, used to determine a hash value of a second file slice set;

[0044] A third determination module, configured to determine the name of the first file slice according to the hash value of the second file slice set;

[0045] An obtaining module, used for obtaining a target first file slice set according to the name of the first file slice and the first file slice set;

[0046] The sending module is used to send the target first file slice set to the server, so that the server merges the first file slices according to the names of the first file slices in the target first file slice set to obtain the target file.

[0047] In a third aspect, the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor;

[0048] Memory stores computer-executable instructions;

[0049] The processor executes the computer-executable instructions stored in the memory to implement the method in the present application.

[0050] In a fourth aspect, the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the method of the present application.

[0051] The present application provides a method, apparatus, device and storage medium for uploading a file. The method comprises: determining a first file slice set, wherein the first file slice set includes a first file slice, and the slice size of the first file slice meets the preset slice size requirement; generating a second file slice set according to the first file slice at a target position and the first file slice at other positions in the first file slice set, wherein the second file slice set includes a target second file slice and other second file slices, wherein the target second file slice corresponds to the first file slice at the target position, and the other second file slices are generated according to the target position bytes in the first file slice at other positions; determining a hash value of the second file slice set; determining a name of the first file slice according to the hash value of the second file slice set; obtaining a target first file slice set according to the name of the first file slice and the first file slice set; and sending the target first file slice set to a server, so that the server merges the first file slices according to the names of the first file slices in the target first file slice set to obtain a target file. Other second file slices are generated by the target position bytes in the first file slices at other positions, and a second file slice set is obtained by the other second file slices and the target second file slices. Then, the effect of the second file slice set is calculated, which reduces the time of hash calculation, thereby reducing the time of file upload and reducing the risk of file upload getting stuck. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0053] Figure 1 A flowchart of a file uploading method provided in an embodiment of the present application;

[0054] Figure 2 A flowchart of another file uploading method provided in an embodiment of the present application;

[0055] Figure 3 A schematic diagram of a process for obtaining a first file slice set and a second file slice set is provided for an embodiment of the present application;

[0056] Figure 4 A schematic diagram of the structure of a file upload device provided in an embodiment of the present application;

[0057] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0058] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0059] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0060] In the prior art, on the one hand, directly sending an upload request may encounter file upload timeout (the front-end framework or other proxy / gateway limits the maximum request duration), file size exceeds the limit (the back-end may limit the size of a single request), upload takes a long time, upload fails due to various network reasons, and needs to be re-uploaded after the upload fails. On the other hand, if the file is sliced, a separate request for the file slice is made. If the file is too large, there are too many slices, and too many http links can easily cause the browser to be overloaded; at the same time, when the file slices are uploaded, the unique value hash of the file is additionally carried when each slice is sent. There are currently two ways to determine the hash value: on the one hand, the file name is used as the hash value. The disadvantage of this method is that once the file name is modified during the upload process, the upload will fail. On the other hand, md5 is used to calculate the hash value of the file content itself. The advantage of this method is that as long as the file content does not change, the hash value will not change. The disadvantage is that the file is too large, and the calculation of the hash value itself is also relatively time-consuming, which may cause the UI to be blocked, resulting in a pseudo-dead state of the page, affecting the user experience.

[0061] In order to solve the above problems, the present application provides a method, apparatus, device and storage medium for uploading a file, which divides the original uploaded file into a first file slice set according to a preset size, and then retains the header and tail first file slices in the first file slice set to obtain a target second file slice; then extracts bytes at the target position from non-header slices and non-tail slices to obtain other second file slices; obtains a second file slice set through the second file slices and the target second file slices; determines a hash value of the second file slice set; then determines the name of the first file slice according to the hash value of the second file slice set; obtains a target first file slice set according to the name of the first file slice and the first file slice set, and then limits the number of concurrent uploads to the server; sends the target first file slice set to the server, so that the server merges the first file slices according to the names of the first file slices in the target first file slice set to obtain the target file. Among them, by extracting the bytes at the target position, other second file slices are obtained, thereby obtaining a second file slice set. The length of the second file slice set is shorter than that of the first file slice set. The time for calculating the hash value of the second file slice set is much shorter than the hash value of the original uploaded file directly generated in the prior art. It can meet the requirement that different hash values ​​calculated for uploading different original files are different, thus shortening the file upload time. At the same time, limiting the number of concurrent requests can prevent a large number of upload requests from being sent in a short period of time, resulting in blocking of the UI, causing the page to be in a suspended state, and affecting the user experience.

[0062] The execution subject of a method for uploading a file provided in an embodiment of the present application may be a server. The server may be any server. This embodiment does not impose any special restrictions on the implementation method of the execution subject, as long as the execution subject can determine a first file slice set, the first file slice set includes a first file slice, and the slice size of the first file slice meets the preset slice size requirement; generate a second file slice set according to the first file slice at the target position and the first file slice at other positions in the first file slice set, wherein the second file slice set includes a target second file slice and other second file slices, the target second file slice corresponds to the first file slice at the target position, and the other second file slices are generated according to the target position bytes in the first file slice at other positions; determine the hash value of the second file slice set; determine the name of the first file slice according to the hash value of the second file slice set; obtain the target first file slice set according to the name of the first file slice and the first file slice set; send the target first file slice set to the server, so that the server merges the first file slices according to the names of each first file slice in the target first file slice set to obtain the target file.

[0063] Hash refers to Hash, which is generally translated as hash, hash, or transliterated as hash. It transforms an input of arbitrary length (also called pre-image) into an output of fixed length through a hash algorithm. The output is the hash value. This conversion is a compression mapping, that is, the space of hash values ​​is usually much smaller than the space of inputs. Different inputs may hash to the same output, so it is impossible to determine the unique input value from the hash value. Simply put, it is a function that compresses a message of arbitrary length to a message digest of a fixed length.

[0064] Byte refers to Byte, which is a unit of measurement used in computer information technology to measure storage capacity. It also represents data types and language characters in some computer programming languages. A byte stores an 8-bit unsigned number with a storage value range of 0-255. Like characters, variables of byte type only need one byte (8 bits) of memory space to store.

[0065] Time slicing refers to time slices. In simple terms, time slices are the time that the CPU allocates to each program, so that each program appears to be running at the same time without wasting CPU resources.

[0066] Figure 1 A flowchart of a method for uploading a file provided in an embodiment of the present application is shown below. Figure 1 As shown, the execution subject of the method can be a server or other servers, and this embodiment is not particularly limited here. Figure 1 As shown, the method includes:

[0067] S101: Determine a first file slice set, where the first file slice set includes a first file slice, and a slice size of the first file slice meets a preset slice size requirement.

[0068] Among them, the first file slice set can be obtained by cutting the file to be uploaded according to the preset slice size requirement; the file to be uploaded can be a large file that occupies more memory, and a large file refers to a file whose size exceeds a certain threshold, usually a file of several hundred megabytes or tens of megabytes; the preset slice size requirement can be any size, as long as it is smaller than the large file size, so that the first file slice can be uploaded quickly; the first file slice size can be 2M, 3M, or 4M; for example, the file size to be uploaded can be 201M, and the preset slice size requirement is 2M, then the first file slice set is 2M file, 2M file, 2M file, 2M file... (a total of 100 2M files), and 1M file.

[0069] S102. Generate a second file slice set according to the first file slice at the target position and the first file slice at other positions in the first file slice set, wherein the second file slice set includes the target second file slice and other second file slices, the target second file slice corresponds to the first file slice at the target position, and the other second file slices are generated according to the target position bytes in the first file slice at other positions.

[0070] The target location may refer to the first first file slice and the last first file slice in the first file slice set, and other locations may refer to other first file slices in the first file slice set except the first file slice at the target location.

[0071] In the embodiment of the present application, generating a second file slice set according to the first file slice at the target position and the first file slice at other positions in the first file slice set includes:

[0072] Determine a target position and other positions in the first file slice set, a first file slice at the target position, and a first file slice at other positions, wherein the target position is a head position and a tail position of the first file slice set;

[0073] Determine the first file slice in the first file slice set at the target position as the target second file slice;

[0074] Determine a target position byte in the first file slice at another position, wherein the target position byte is in the first file slice at another position;

[0075] Generate other second file slices according to the target position bytes in the first file slices at other positions;

[0076] A second file slice set is obtained according to the target second file slice and other second file slices.

[0077] Among them, the first file slices at the head and tail positions in the first file slice file set, that is, the first file slice and the last file slice in the first file slice file set are retained as the target second file slices; other first file slices at non-head and tail positions in the first file slice set are first file slices at other positions, wherein the first first file slice in the first file set slice set is retained because there is more distinguishing information between the slices at the first position of different uploaded files, and the hash values ​​obtained by hashing different files can be different while shortening the file length of the hash calculation and thus shortening the hash calculation time; the last first file slice in the entire first file set slice set is retained because the last slice may be insufficient in length, resulting in the failure to obtain the target position bytes.

[0078] The target position bytes may refer to the two bytes at the head position, the two bytes in the middle position, and the two bytes at the tail position of the first file slice from other positions; or may refer to the three bytes at the head position, the three bytes in the middle position, and the three bytes at the tail position of the first file slice from other positions; or may refer to the three bytes at the head position and the three bytes at the tail position of the first file slice from other positions. As long as the target position bytes can make the file length of the final set of second file slices shorter than the originally uploaded file, and different hash values ​​can be obtained by uploading different files, the more bytes occupied by the target position bytes and the wider the distribution of the target bytes in the first file slice, the more different the final set of second file slices will be, thereby obtaining different hash values.

[0079] Keep the first and last first file slices of the first file slice set to form the second target file slice; obtain the target position bytes in the remaining first file slices to form other second file slices; finally, form the second file slices based on the second target file slices and other second file slices. For example: the first file slice set is 2M file (first), 2M file (second), 2M file (third), 2M file (fourth)...2M file (hundredth), 1M file (two hundred and first), then the second target file slice is: 2M file (first), 1M file, and the other second file slices are: 2M file (second), 2M file (third), 2M file (fourth)...2M file (two hundredth); if one of the 2M files in the second target file slice is represented by bytes as the smallest unit to represent the position range occupied by its file, it means that The position range is [0, 2097152]. If the target position bytes can refer to the two bytes at the head position, the two bytes in the middle position, and the two bytes at the end of the first file slice from other positions, then the target position bytes are: [0, 2] (i.e., the two bytes at the head position), [1048576, 1048578] (i.e., the two bytes in the middle position, 1048576 is obtained by dividing (0+2097152) / 2, and 1048578 is obtained by dividing 1048576+2), and [2097150, 2097152] (i.e., the two bytes at the end).

[0080] S103: Determine a hash value of the second file slice set.

[0081] The hash value may be calculated by using a hash algorithm to calculate the hash value of the second file slice set, wherein the hash algorithm includes: MD5 (Message-Digest Algorithm 5) algorithm, SHA-1 (Secure Hash Algorithm 1) algorithm, and SHA-256 (Secure Hash Algorithm 1, Secure Hash Algorithm 256).

[0082] In this embodiment of the present application, determining the hash value of the second file slice set includes:

[0083] Get the execution priority of each task in the file upload system;

[0084] Determine the available time slices in the file upload system according to the execution priority of each task in the file upload system;

[0085] If the available time slices meet the preset time slice requirements, the available time slices are used to determine the hash value of the second file slice set.

[0086] In the embodiment of the present application, after determining the available time slices in the file upload system according to the execution priority of each task in the file upload system, the method further includes:

[0087] If the available time slice does not meet the preset time slice requirement, the task whose execution priority meets the preset priority requirement is executed in the file upload system until the available time slice meets the preset time slice requirement, and then the available time slice is used to determine the hash value of the second file slice set.

[0088] Among them, time slicing is the time slice, that is, the time allocated by the CPU (Central Processing Unit) to each program. Each thread is assigned a time period, called its time slice, that is, the time the process is allowed to run, so that each program appears to be running simultaneously.

[0089] Calculating the hash value of the second file slice set is part of the file upload task, and the file upload task is a low priority task; if there is a high priority task when preparing to start calculating the hash value of the second file slice set, the time slice will be allocated to the high priority task first to execute the high priority task; in the middle of calculating the hash value of the second file slice set, if there is a high priority task, the calculation of the hash value of the second file slice set will be stopped, the time slice allocated to the task of calculating the hash value of the second file slice will be deprived, and then allocated to the high priority task to execute the high priority task first; if there is no high priority task or the high priority task is completed, the time slice will be allocated to the task of calculating the hash value of the second file slice set. The high priority task can be page rendering, data request, and other tasks that affect the normal use of user functions.

[0090] S104. Determine the name of the first file slice according to the hash value of the second file slice set.

[0091] The hash value of the second file slice set is used as the hash value of the first file slice set.

[0092] In the embodiment of the present application, determining the name of the first file slice according to the hash value of the second file slice set includes:

[0093] Determine a sorting identifier of each first file slice in the first file slice set;

[0094] The names of the first file slices are determined according to the sorting identifiers of the first file slices in the first file slice set and the hash values ​​of the second file slice set.

[0095] Among them, the name of the first file slice is: the hash value of the first file slice set - the slice sorting name. For example, the hash value of the second file slice set is hash1, then the hash value of the first file slice set is also hash1. If the first file slice set is: 2M file (first), 2M file (second), 2M file (third), 2M file (fourth)...2M file (hundredth), 1M file (two hundred and first), then the names of the slices of the first file slice set can be: hash1-1, hash1-2, hash1-3, hash1-4,...hash1-100, hash1-101.

[0096] S105, obtaining a target first file slice set according to the name of the first file slice and the first file slice set;

[0097] S106: Send the target first file slice set to the server, so that the server merges the first file slices according to the names of the first file slices in the target first file slice set to obtain the target file.

[0098] Wherein, according to the hash value of the first file slice set in the name of the first file slice, the merging is performed according to the slice sorting part of the first file slice.

[0099] In the embodiment of the present application, the target first file slice set is sent to the server, so that the server merges the first file slices according to the names of the first file slices in the target first file slice set to obtain the target file, including:

[0100] Determine the preset number of concurrent uploads in the file upload system;

[0101] According to the concurrency number preset in the file upload system, a first file slice upload request corresponding to the concurrency number is sent to the server, so that the server writes the name of the first file slice in the first file slice upload request into the uploaded slice name list in the server, wherein the first file slice upload request is generated according to the first file slice in the target first file slice set;

[0102] Determining, according to the first file slice upload request, an upload progress of a first file slice in a target first file slice set from an upload list;

[0103] If the upload progress indicates that the target first file slice set has been uploaded, all first file slice upload requests in the upload list are deleted, and the server merges the first file slices according to the names of the first file slices in the target first file slice set to obtain the target file.

[0104] Among them, the preset concurrent number is to avoid the file being too large, which will lead to too many first file slices, resulting in too many first file slice upload requests being sent at one time during the first file slice upload process, causing excessive load on the browser and the backend during the TCP (Transmission Control Protocol) establishment process, affecting the file upload function. The concurrent number can be 5 or 10, as long as it does not affect the file upload function.

[0105] The first file slice upload request may be an XHR (ie, XML Http Request) object, where XML is an Extensible Markup Language (Extensible Markup Language).

[0106] The upload list is used to save the first file slice upload request corresponding to the first file slice being uploaded; the first upload list can be an array; if the first file slice corresponding to a first file slice upload request in the upload list has been uploaded, the first file slice upload request will be deleted from the upload list; until the first file slices in all first file slice sets have been uploaded, the corresponding first file slice upload request in the upload list will also be deleted.

[0107] Among them, in the embodiment of the present application, after sending a first file slice upload request corresponding to the concurrent number to the server according to the concurrent number preset in the file upload system, so that the server writes the name of the first file slice in the first file slice upload request into the uploaded slice name list in the server, the method also includes:

[0108] receiving target instructions;

[0109] Determine the status of the first file slice upload request according to the target instruction;

[0110] If the status of the first file slice upload request is upload interruption or upload pause, all first file slice upload requests in the file upload system are cleared.

[0111] Among them, the target instruction may be an instruction issued for performing related operations when the user needs to cancel or pause file upload; it may also be an instruction issued by the system due to poor network or network disconnection; the target instruction can indicate the interruption of the upload of the first file slice, or it can indicate the suspension of the upload of the first file slice.

[0112] Clearing all first file slice upload requests in the file upload system means clearing all first file slice upload requests in the upload list.

[0113] When the status of the first file slice upload request is upload interruption or upload pause, all first file slice requests in the upload list will be cleared.

[0114] In the embodiment of the present application, if the status of the first file slice upload request is upload interruption or upload suspension, after clearing all first file slice upload requests in the file upload system, the method further includes:

[0115] Get the list of uploaded slice names in the server;

[0116] According to the uploaded slice name list and the concurrent number, re-execute the step of sending the first file slice upload request corresponding to the concurrent number to the server, so that the server writes the name of the first file slice in the first file slice upload request into the uploaded slice name list in the server.

[0117] Among them, if the status of the first file slice upload request is upload interruption or upload pause, it is necessary to reconnect to upload the remaining first file slices, obtain the list of uploaded slice names in the server, and then upload the remaining first file slices.

[0118] The present application provides a method for uploading files. On the basis of the current file slice uploading, on the one hand, a second file slice set shorter than the first file slice set is obtained, and then a hash value of the second file slice set is calculated, and the hash value of the second file slice set is used as the hash value of the first file slice set, thereby obtaining the name of the first file slice set, thereby shortening the hash calculation time; at the same time, the number of concurrent requests is limited to prevent a large number of upload requests from being sent in a short period of time, resulting in blocking of the UI and causing a suspended state of the page, thereby improving the user experience.

[0119] Figure 2 A flowchart of another file uploading method provided in an embodiment of the present application. Figure 2 As shown, the execution subject of the method can be a server or other servers, and this embodiment is not particularly limited here. Figure 2 As shown, the method includes:

[0120] S201: Obtain a first file slice set and a second file slice set.

[0121] The process of obtaining the first file slice set and the second file slice set is as follows: Figure 3 As shown: the file to be uploaded is divided according to the preset size to obtain the first file slice set, where the preset size can be 2M; if the remaining last slice is less than 2M, it is divided into a slice separately. The first slice and the last slice in the first file slice set are retained, which are the target second file slices; then the first, middle and last 2 bytes of the middle slice are taken to splice into small slice blocks to obtain other second file slices, and the target second file slice and other second file slices are merged to obtain the second file slice set.

[0122] S202: Calculate the hash value of the second file slice set, and obtain the name of the first file slice in the first file slice set.

[0123] Among them, the method for calculating the hash value of the second file slice set is: if there is a high-priority task when preparing to start calculating the hash value of the second file slice set, the time slice will be allocated to the high-priority task first to execute the high-priority task; in the middle of calculating the hash value of the second file slice set, if there is a high-priority task, the calculation of the hash value of the second file slice set will be stopped, the time slice allocated to the task of calculating the hash value of the second file slice will be deprived, and then allocated to the high-priority task, so as to execute the high-priority task first; if there is no high-priority task or the high-priority task is completed, the time slice will be allocated to the task of calculating the hash value of the second file slice set, and the high-priority task can be page rendering, data request and other tasks that affect the normal use of user functions.

[0124] The method for obtaining the name of the first file slice is: the hash value of the first file slice set minus the order of the first file slice, and the hash value of the first file slice set is the hash value of the second file slice set.

[0125] S203: Upload the first file slice in the first file slice set according to the limited concurrent quantity.

[0126] The concurrent limit can be 5 or 10.

[0127] The method for uploading the first file slice in the first file slice set is: according to the preset concurrent number, sending an xhr request to the server to upload the first file slice corresponding to the preset concurrent number; saving the xhr object of each uploaded first file slice using an array, and after successfully uploading a first file slice, deleting the xhr object corresponding to the first file slice from the array.

[0128] S204: The server creates a new folder to store the uploaded first file slice, and adds the name of the uploaded first file slice to the uploaded slice list.

[0129] S205. If the upload of the first file slice is interrupted / paused, all xhr requests in the array are canceled and cleared; if the first file slice is uploaded again, the upload is continued in a breakpoint resume mode.

[0130] Among them, the method of resuming breakpoint upload is: request the server to obtain the list of uploaded slices; if the current slice has been saved on the server, directly prompt that the upload is successful (the file is uploaded in seconds); if the current slice is not saved on the server, send an xhr request to the server to upload the first file slice corresponding to the preset concurrent number; save the xhr object of each uploaded first file slice using an array, and after successfully uploading a first file slice, delete the xhr object corresponding to the first file slice from the array; add the name of the uploaded first file slice to the list of uploaded slices.

[0131] S206: After all first file slices in the first file slice set have been uploaded, the server merges the first file slices.

[0132] Among them, the server merges the first file slices in the following method: sending a slice merge request to the server, and the server merges the first file slices in order according to the name of the first file slice (hash value of the first file slice set - the order of the first file slice).

[0133] The present application provides another method for uploading files. On the basis of the current file slice uploading, the hash calculation adopts the method of calculating the hash of the second file slice set to improve the user experience, avoiding the problem of too large files and too long time to calculate the hash value; uploading files adopts the method of concurrent network request uploading, which solves the problem of too many files being uploaded at one time, causing the browser to be overloaded and may cause a white screen of the page; if the upload is interrupted / paused, the breakpoint resume method is used to continue the upload, which can clear all xhr requests in time, avoiding the problem of invalid requests and waiting.

[0134] Figure 4 This is a diagram showing an example of the structure of a file upload device provided in an embodiment of the present application. Figure 4 As shown, the file uploading device 40 includes: a first determining module 401, a generating module 402, a second determining module 403, a third determining module 404, an obtaining module 405, and a sending module 406. Among them:

[0135] A first determining module 401 is used to determine a first file slice set, where the first file slice set includes a first file slice, and a slice size of the first file slice meets a preset slice size requirement;

[0136] A generating module 402 is used to generate a second file slice set according to the first file slice at the target position and the first file slices at other positions in the first file slice set, wherein the second file slice set includes the target second file slice and other second file slices, the target second file slice corresponds to the first file slice at the target position, and the other second file slices are generated according to the target position bytes in the first file slice at other positions;

[0137] A second determination module 403, used to determine a hash value of a second file slice set;

[0138] A third determination module 404 is used to determine the name of the first file slice according to the hash value of the second file slice set;

[0139] An obtaining module 405 is used to obtain a target first file slice set according to the name of the first file slice and the first file slice set;

[0140] The sending module 406 is used to send the target first file slice set to the server, so that the server merges the first file slices according to the names of the first file slices in the target first file slice set to obtain the target file.

[0141] In the embodiment of the present application, the generating module 402 may also be specifically used for:

[0142] Determine a target position and other positions in the first file slice set, a first file slice at the target position, and a first file slice at other positions, wherein the target position is a head position and a tail position of the first file slice set;

[0143] Determine the first file slice in the first file slice set at the target position as the target second file slice;

[0144] Determine a target position byte in the first file slice at another position, wherein the target position byte is in the first file slice at another position;

[0145] Generate other second file slices according to the target position bytes in the first file slices at other positions;

[0146] A second file slice set is obtained according to the target second file slice and other second file slices.

[0147] In the embodiment of the present application, the second determining module 403 may also be specifically used for:

[0148] Get the execution priority of each task in the file upload system;

[0149] Determine the available time slices in the file upload system according to the execution priority of each task in the file upload system;

[0150] If the available time slices meet the preset time slice requirements, the available time slices are used to determine the hash value of the second file slice set.

[0151] In the embodiment of the present application, the second determining module 403 may also be specifically used for:

[0152] If the available time slice does not meet the preset time slice requirement, the task whose execution priority meets the preset priority requirement is executed in the file upload system until the available time slice meets the preset time slice requirement, and then the available time slice is used to determine the hash value of the second file slice set.

[0153] In the embodiment of the present application, the third determining module 404 is further specifically configured to:

[0154] Determine a sorting identifier of each first file slice in the first file slice set;

[0155] The names of the first file slices are determined according to the sorting identifiers of the first file slices in the first file slice set and the hash values ​​of the second file slice set.

[0156] In the embodiment of the present application, the sending module 406 is further specifically used for:

[0157] Determine the preset number of concurrent uploads in the file upload system;

[0158] According to the concurrency number preset in the file upload system, a first file slice upload request corresponding to the concurrency number is sent to the server, so that the server writes the name of the first file slice in the first file slice upload request into the uploaded slice name list in the server, wherein the first file slice upload request is generated according to the first file slice in the target first file slice set;

[0159] Determining, according to the first file slice upload request, an upload progress of a first file slice in a target first file slice set from an upload list;

[0160] If the upload progress indicates that the target first file slice set has been uploaded, all first file slice upload requests in the upload list are deleted, and the server merges the first file slices according to the names of the first file slices in the target first file slice set to obtain the target file.

[0161] In the embodiment of the present application, the sending module 406 is further specifically used for:

[0162] receiving target instructions;

[0163] Determine the status of the first file slice upload request according to the target instruction;

[0164] If the status of the first file slice upload request is upload interruption or upload pause, all first file slice upload requests in the file upload system are cleared.

[0165] In the embodiment of the present application, the sending module 406 is further specifically used for:

[0166] Get the list of slice names uploaded to the server;

[0167] According to the uploaded slice name list and the concurrent number, re-execute the step of sending the first file slice upload request corresponding to the concurrent number to the server, so that the server writes the name of the first file slice in the first file slice upload request into the uploaded slice name list in the server.

[0168] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 5 As shown, the electronic device 50 includes:

[0169] The electronic device 50 may include a processor 501 with one or more processing cores, a memory 502 with one or more computer-readable storage media, a communication component 503 and other components. The processor 501 , the memory 502 and the communication component 503 are connected via a bus 505 .

[0170] In a specific implementation process, at least one processor 501 executes the computer execution instructions stored in the memory 502, so that at least one processor 501 executes the above file uploading method.

[0171] The specific implementation process of the processor 501 can be found in the above method embodiment, and its implementation principle and technical effect are similar, so this embodiment will not be repeated here.

[0172] In the above Figure 5 In the illustrated embodiment, it should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.

[0173] The memory may include a high-speed memory (Random Access Memory, RAM), and may also include a non-volatile memory (Non-volatile Memory, NVM), such as at least one disk memory.

[0174] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.

[0175] In some embodiments, a computer program product is also proposed, including a computer program or instructions, which implement the steps in any of the above-mentioned file uploading methods when executed by a processor.

[0176] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0177] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.

[0178] To this end, an embodiment of the present application provides a computer-readable storage medium, in which multiple instructions are stored. The instructions can be loaded by a processor to execute the steps in any file uploading method provided in the embodiment of the present application.

[0179] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0180] According to one aspect of the present application, a computer program product or a computer program is provided. The computer program product or the computer program comprises computer instructions stored in a computer-readable storage medium.

[0181] Since the instructions stored in the storage medium can execute the steps in any file uploading method provided in the embodiments of the present application, the beneficial effects that can be achieved by any file uploading method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.

[0182] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.

[0183] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A file uploading method, characterized in that: Applied to a file upload system, the method comprises: Determine a first file slice set, where the first file slice set includes a first file slice, and a slice size of the first file slice meets a preset slice size requirement; Generate a second file slice set according to the first file slice at the target position and the first file slice at other positions in the first file slice set, wherein the second file slice set includes a target second file slice and other second file slices, the target second file slice corresponds to the first file slice at the target position, and the other second file slices are generated according to the target position bytes in the first file slice at other positions; Determine a hash value of the second file slice set; Determine the name of the first file slice according to the hash value of the second file slice set; Obtaining a target first file slice set according to the name of the first file slice and the first file slice set; The target first file slice set is sent to a server, so that the server merges the first file slices according to the names of the first file slices in the target first file slice set to obtain a target file.

2. The method according to claim 1, characterized in that The generating a second file slice set according to the first file slice at the target position and the first file slice at other positions in the first file slice set comprises: Determine a target position and other positions in the first file slice set, a first file slice at the target position, and a first file slice at the other positions, wherein the target position is a head position and a tail position of the first file slice set; Determine the first file slice in the first file slice set at the target position as the target second file slice; Determine a target position byte in the first file slice at the other position, wherein the target position byte is in the first file slice at the other position; Generate the other second file slice according to the target position byte in the first file slice at the other position; The second file slice set is obtained according to the target second file slice and the other second file slices.

3. The method according to claim 1, characterized in that The determining the hash value of the second file slice set includes: Obtaining the execution priority of each task in the file upload system; Determining available time slices in the file upload system according to the execution priority of each task in the file upload system; If the available time slice meets the preset time slice requirement, the available time slice is used to determine the hash value of the second file slice set.

4. The method according to claim 3, characterized in that After determining the available time slices in the file upload system according to the execution priority of each task in the file upload system, the method further includes: If the available time slice does not meet the preset time slice requirement, the task whose execution priority meets the preset priority requirement is executed in the file upload system until the available time slice meets the preset time slice requirement, and then the available time slice is used to determine the hash value of the second file slice set.

5. The method according to claim 1, characterized in that The determining the name of the first file slice according to the hash value of the second file slice set includes: Determining a sorting identifier of each first file slice in the first file slice set; Determine the name of the first file slice according to the sorting identifier of each first file slice in the first file slice set and the hash value of the second file slice set.

6. The method according to claim 1, characterized in that The step of sending the target first file slice set to a server so that the server merges the first file slices according to the names of the first file slices in the target first file slice set to obtain a target file includes: Determine the preset concurrent number in the file upload system; According to a preset concurrent number in the file upload system, a first file slice upload request corresponding to the concurrent number is sent to the server, so that the server writes the name of the first file slice in the first file slice upload request into a list of uploaded slice names in the server, wherein the first file slice upload request is generated according to the first file slice in the target first file slice set; Determining, according to the first file slice upload request, an upload progress of a first file slice in a target first file slice set from an upload list; If the upload progress indicates that the target first file slice set has been uploaded, all first file slice upload requests in the upload list are deleted, and the server is enabled to merge the first file slices according to the names of the first file slices in the target first file slice set to obtain the target file.

7. The method according to claim 6, characterized in that After sending a first file slice upload request corresponding to the concurrent number to the server according to the concurrent number preset in the file upload system, so that the server writes the name of the first file slice in the first file slice upload request into the uploaded slice name list in the server, the method further includes: receiving target instructions; Determine the status of the first file slice upload request according to the target instruction; If the status of the first file slice upload request is upload interruption or upload pause, all first file slice upload requests in the file upload system are cleared.

8. The method according to claim 7, characterized in that If the state of the first file slice upload request is upload interruption or upload suspension, after clearing all first file slice upload requests in the file upload system, the method further includes: Obtain a list of uploaded slice names in the server; According to the uploaded slice name list and the concurrent number, the step of sending the first file slice upload request corresponding to the concurrent number to the server is re-executed so that the server writes the name of the first file slice in the first file slice upload request into the uploaded slice name list in the server.

9. A file uploading device, characterized in that: include: A first determining module is used to determine a first file slice set, where the first file slice set includes a first file slice, and a slice size of the first file slice meets a preset slice size requirement; a generating module, configured to generate a second file slice set according to the first file slice at the target position and the first file slice at other positions in the first file slice set, wherein the second file slice set includes the target second file slice and other second file slices, the target second file slice corresponds to the first file slice at the target position, and the other second file slices are generated according to the target position bytes in the first file slice at other positions; A second determination module, used to determine a hash value of the second file slice set; a third determining module, configured to determine a name of the first file slice according to a hash value of the second file slice set; An obtaining module, used for obtaining a target first file slice set according to the name of the first file slice and the first file slice set; The sending module is used to send the target first file slice set to the server, so that the server merges the first file slices according to the names of the first file slices in the target first file slice set to obtain the target file.

10. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 8 when executed by a processor.

Citation Information

Patent Citations

  • Task scheduling method in cloud computing environment

    CN103324525A

  • File transmission scheduling method, device and equipment and computer readable storage medium

    CN110008187A

  • Task scheduling method and device, equipment and storage medium

    CN114860403A

  • File fragment uploading method and device, vehicle and storage medium

    CN116112484A

  • File slice uploading method and apparatus, and cloud storage system

    WO2018059222A1