File processing method and device, electronic equipment and storage medium
By dynamically adjusting the size of file shards, and according to changes in the network environment, the problem of low efficiency and stability of fixed shard sizes in complex network environments is solved, and more efficient and stable file uploads are achieved.
Patent Information
- Application Number
- CN202411685168.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-04-04
- Estimated Expiration
- 2044-11-22
AI Technical Summary
In a complex and changeable network environment, the fixed shard size is difficult to adapt, resulting in the impact of file upload efficiency and stability.
By obtaining the initial shard value and change relationship, dynamically adjust the target shard value, and switch different change relationships according to the network response speed parameter value to adapt to changes in the network environment.
It realizes the adaptability of file upload, improves the efficiency and stability of file upload, and can better utilize network resources.
Smart Images

Figure CN119766798A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a file processing method and device, electronic equipment, and storage medium. Background Art
[0002] With the rapid development of Internet communication technology, the efficiency of data transmission has been continuously improved.
[0003] File uploading is a common data transmission scenario. For small files, uploading a file at a time can usually be completed quickly. However, for large files, due to the limitations of the network environment, uploading a file at a time may be interrupted or even fail.
[0004] In the related art, by uploading files in pieces according to a fixed piece size, the risk of upload interruption or even failure due to poor network conditions can be reduced. However, uploading with a fixed piece size is still difficult to adapt to complex and changeable network environments, affecting the efficiency and stability of file upload. Summary of the invention
[0005] In view of the above problems, a method and device for file processing, an electronic device, and a storage medium are proposed to overcome the above problems or at least partially solve the above problems, including:
[0006] A method for file processing, the method comprising:
[0007] In response to a request to upload a file, an initial shard value and a first change relationship are obtained; wherein the first change relationship indicates that the target shard value of the file increases at a preset rate as time increases;
[0008] Uploading the file in pieces according to the initial piece value and the first change relationship;
[0009] In the process of uploading the file in pieces according to the initial piece value and the first change relationship, obtaining a network response speed parameter value;
[0010] If the network response speed parameter value does not meet the preset threshold, a second change relationship is obtained; wherein the second change relationship indicates that the target shard value increases with time, and the change rate of the target shard value decreases with time;
[0011] According to the second change relationship, uploading the unfinished portion of the file in segments;
[0012] Feedback the upload result of the file.
[0013] Optionally, in the process of uploading the incompletely uploaded portion of the file in pieces according to the second change relationship, the method further includes:
[0014] Get the maximum shard value;
[0015] If the target fragment value is greater than or equal to the maximum fragment value, the unfinished portion of the file is uploaded in fragments according to the maximum fragment value.
[0016] Optionally, before obtaining the initial shard value, the method further includes:
[0017] Acquire first network environment data; wherein the first network environment data is network environment data corresponding to the first network connected by the client, and the network environment data includes one or more of the following: network connection type, network bandwidth information, and communication protocol information;
[0018] Determining a network environment indicator value of the first network according to the first network environment data;
[0019] The initial fragmentation value and the maximum fragmentation value are determined according to the network environment indicator value.
[0020] Optionally, uploading the file in pieces according to the initial piece value and the first change relationship includes:
[0021] The file is uploaded in pieces using the initial piece value as the target piece value, and the target piece value is increased according to the first change relationship at a first preset time interval; wherein, in adjacent time intervals, the target piece value of the latter time interval is a preset multiple of the target piece value of the previous time interval.
[0022] Optionally, the second change relationship is a logarithmic function relationship, the logarithmic function relationship also includes a preset constant, and uploading the unuploaded portion of the file in pieces according to the second change relationship includes:
[0023] Determine the target fragmentation value according to the second change relationship, and upload the unfinished portion of the file in fragments according to the target fragmentation value;
[0024] At a second preset time interval, the target sharding value is increased according to the second corresponding relationship; wherein, in adjacent time intervals, the target sharding value of the latter time interval and the target sharding value of the previous time interval satisfy the logarithmic function relationship.
[0025] Optionally, the method further comprises:
[0026] In response to the operation of switching the network connection of the client, obtaining second network environment data; wherein the second network environment data is network environment data corresponding to the second network connected to the client after switching the network connection;
[0027] Determining a second network environment indicator value of the second network according to the second network environment data;
[0028] The initial fragmentation value and the maximum fragmentation value are re-determined according to the second network environment indicator value.
[0029] Optionally, the method further comprises:
[0030] Save the uploaded data of each slice of the file; wherein the uploaded data includes one or more of the following: the target slice value corresponding to each slice, the sequence number corresponding to each slice, the size information of the file, and the unique identifier corresponding to each slice;
[0031] Determine whether there are shards that failed to be uploaded;
[0032] If there are segments that failed to be uploaded, the segments that failed to be uploaded are re-uploaded according to the uploaded data.
[0033] A device for file processing, comprising:
[0034] An initial sharding value and first change relationship acquisition module, used to obtain an initial sharding value and a first change relationship in response to a request to upload a file; wherein the first change relationship indicates that the target sharding value of the file increases at a preset rate as time increases;
[0035] A first fragment uploading module, used for uploading the file in fragments according to the initial fragment value and the first change relationship;
[0036] A response speed parameter value acquisition module, used for acquiring a network response speed parameter value in the process of uploading the file in pieces according to the initial piece value and the first change relationship;
[0037] A second change relationship acquisition module, configured to acquire a second change relationship if the network response speed parameter value does not meet a preset threshold; wherein the second change relationship indicates that the target shard value increases with time, and the change rate of the target shard value decreases with time;
[0038] A second piecewise uploading module, configured to upload the unuploaded portion of the file in pieces according to the second change relationship;
[0039] The upload result feedback module is used to feedback the upload result of the file.
[0040] An electronic device comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the above-mentioned file processing method when executed by the processor.
[0041] A computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the file processing method as described above is implemented.
[0042] The embodiment of the present invention has the following advantages: by responding to a request to upload a file, an initial fragmentation value and a first change relationship are obtained, wherein the first change relationship represents that the target fragmentation value of the file increases at a preset rate as time increases, and the file is uploaded in pieces according to the initial fragmentation value and the first change relationship. In the process of uploading the file in pieces according to the initial fragmentation value and the first change relationship, a network response speed parameter value is obtained. If the network response speed parameter value does not meet the preset threshold, a second change relationship is obtained, wherein the second change relationship represents that the target fragmentation value increases as time increases, and the rate of change of the target fragmentation value decreases as time increases. According to the second change relationship, the part of the file that has not been uploaded is uploaded in pieces, and the upload result of the file is fed back, thereby realizing dynamic adjustment of the target fragmentation value, so that the piecewise uploading of the file can adapt to the complex and changeable network environment, which not only improves the efficiency of file uploading, but also improves the stability of file uploading. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solution of the present invention, the accompanying drawings required for use in the description of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0044] Figure 1 is a flowchart of a method for file processing provided by an embodiment of the present invention;
[0045] Figure 2 is a target fragmentation value variation curve diagram provided by an embodiment of the present invention;
[0046] Figure 3 This is a schematic diagram of a format for storing sliced uploaded data provided by an embodiment of the present invention;
[0047] Figure 4 is an implementation flow chart of another file processing method provided by one embodiment of the present invention;
[0048] Figure 5It is a structural block diagram of a file processing device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0049] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] In Internet applications, we often encounter scenarios where we need to upload files. If the uploaded files are not large, such as text files or low-resolution image files, the operation can be completed quickly without much interference. However, if the uploaded files are relatively large files such as high-resolution image files and video files, the waiting time for the upload process is relatively long, and they are easily affected by network fluctuations. If the upload is disconnected in the middle of the process, it needs to be retransmitted. In particular, the real network environment is changeable, which may change from WIFI to 4G, 4G to 3G, etc. The upload is easily interrupted, and it is difficult to successfully transfer large files in one go. In addition, the server may be limited by resources, such as memory, CPU, network bandwidth, etc., making it difficult to transfer large files.
[0051] Related technologies use the method of uploading in pieces to solve this problem. Specifically, a large file is divided into many small pieces, and data such as the piece size, total number of pieces, and piece sequence number are recorded. Each piece is uploaded one at a time. After the upload is completed, a merge request is initiated to notify the server to merge the entire file. This method solves the problem of uploading large files and can solve the problem of insufficient server resource usage to a certain extent. However, the network conditions are relatively complex, the network bandwidth is not perceptible to the client, and the piece size is often fixed, the upload efficiency is relatively low, and the server resources are not better utilized.
[0052] Based on this, the present invention proposes a method that can adapt to network conditions and dynamically adjust the size of uploaded segments to improve resource utilization and upload efficiency.
[0053] The embodiments of the present invention will be described in detail below.
[0054] Reference Figure 1 , shows a flowchart of a method for file processing provided by an embodiment of the present invention, which may specifically include the following steps:
[0055] Step 101, in response to a request to upload a file, obtaining an initial shard value and a first change relationship; wherein the first change relationship indicates that the target shard value of the file increases at a preset rate as time increases;
[0056] In step 101, the target shard value is the shard value when sharding the file. In order to adapt to the complex and changeable network environment, the target shard value is constantly and dynamically adjusted. Therefore, it is necessary to obtain the initial shard value as the target shard value when sharding the file for the first time, and the preset first change relationship. The change relationship defines the change relationship according to which rules the target shard value is adjusted, and the first change relationship defines the increase of the target shard value over time, and increases by a preset multiple. Among them, the initial shard value and the preset multiple can be set according to the needs of the actual situation. For example, referring to the original size of the file, the initial shard value is set to 32mb, 64mb, etc. The preset multiple can control the growth rate of the target shard value, for example, it can be set to 1.5 times, 2 times, etc.
[0057] As an example, the first corresponding relationship may be defined as S=k×S′, where k is a preset multiple, S is a target fragment value required for the current fragment upload, and S′ is a target fragment value during the last fragmentation.
[0058] Step 102, uploading the file in pieces according to the initial piece value and the first change relationship;
[0059] In this embodiment, the stage of uploading files in pieces according to the initial piece value and the first change relationship can be regarded as a rapid growth stage. Because the target piece value is relatively small in this stage, it will not cause too much pressure on the network bandwidth, so the target piece value can be dynamically adjusted according to a preset multiple. Moreover, in this stage, the piece changes from small to large, and its transmission speed also increases accordingly, which can speed up the upload of files.
[0060] In some embodiments of the present invention, step 102 includes:
[0061] The file is uploaded in pieces using the initial piece value as the target piece value, and the target piece value is increased according to the first change relationship at a first preset time interval; wherein, in adjacent time intervals, the target piece value of the latter time interval is a preset multiple of the target piece value of the previous time interval.
[0062] As an example, in adjacent time intervals, let the target fragmentation value of the previous time interval be S', the target fragmentation value of the next time interval be S, the first corresponding relationship be S=2×S', the first preset time interval be 2 seconds, the original size of the file be 1GB (i.e. 1024mb), the initial fragmentation value be defined as 32mb, then the process of uploading the file in fragments is as follows:
[0063] When the file is fragmented for the first time, the file is fragmented according to the initial fragment value to obtain 32 fragments. The size of each fragment (i.e., the target fragment value) is 32 MB, and all fragments are uploaded;
[0064] When the first preset time interval, i.e. 2 seconds, is reached, assuming that a total of 2 segments are successfully uploaded, the remaining portion of the file is 1024-32×2=960mb. According to the first change relationship, the target segment value is increased to 32×2=64mb, and the remaining 960mb of the file is segmented again to obtain 15 segments, each of which is 64mb in size, and all the segments are uploaded again. After another 2 seconds, the target segment value of the previous time interval and the first change relationship are adjusted again, and so on.
[0065] In actual applications, the network environment can be continuously detected when uploading files in pieces. If positive network feedback is obtained, that is, the server responds within a certain time range, it can be considered that the current network environment is good and can withstand greater bandwidth pressure, and the rapid growth stage can be maintained.
[0066] Step 103, in the process of uploading the file in pieces according to the initial piece value and the first change relationship, obtaining a network response speed parameter value;
[0067] In step 103, the network response speed parameter value reflects the relevant parameter value of the current network response speed, such as network delay, packet loss rate, network transmission speed, etc.
[0068] Step 104: if the network response speed parameter value does not meet the preset threshold, a second change relationship is obtained; wherein the second change relationship indicates that the target shard value increases with time, and the change rate of the target shard value decreases with time;
[0069] In step 104, if the network response speed parameter value does not meet the preset threshold, it is considered that the network begins to fluctuate at this time. If the target shard value continues to increase according to the first change relationship in the rapid growth stage, it will not only no longer have a positive impact on the speed, but will reduce the speed in some network environments, thereby affecting the stability and speed of file upload. At this time, the second change relationship is obtained to adjust the adjustment strategy of the target shard value according to the second change relationship. The second change relationship represents that the target shard value increases with time, and the rate of change of the target shard value decreases with time. In other words, at this time, the target shard value is still increasing, but the rate of increase is reduced.
[0070] Step 105: uploading the unfinished portion of the file in pieces according to the second change relationship;
[0071] In step 105, after the rapid growth phase, if it is confirmed that the network response speed parameter value does not meet the preset threshold, the file is uploaded in pieces by applying the second change relationship, so that the piece upload phase enters the slow growth phase.
[0072] In some embodiments of the present invention, the second variation relationship is a logarithmic function relationship, and the logarithmic function relationship also includes a preset constant. Step 105 includes:
[0073] Determine the target fragmentation value according to the second change relationship, and upload the unfinished portion of the file in fragments according to the target fragmentation value;
[0074] At a second preset time interval, the target sharding value is increased according to the second corresponding relationship; wherein, in adjacent time intervals, the target sharding value of the latter time interval and the target sharding value of the previous time interval satisfy the logarithmic function relationship.
[0075] As an example, assuming that the target fragmentation value of the previous time interval is S', and the target fragmentation value of the next time interval is S, the second corresponding relationship is S = C × ln (S ′ +1), where C is a preset constant.
[0076] When entering the slow growth phase, first obtain the target shard value of the last sharding, such as the target shard value of the last sharding in the fast growth phase, and apply the second corresponding relationship to determine the target shard value of this sharding.
[0077] Then, at a second preset time interval, the target fragmentation value is continuously increased according to the second corresponding relationship, and the unfinished upload portion of the file is uploaded in fragments.
[0078] In this slow growth stage, the target shard value shows a normalized slope growth trend. Although it is still increasing, the increase rate is relatively slow to adapt to the more volatile network environment. While ensuring a certain file transfer rate, it also guarantees the stability of file transfer.
[0079] In practical applications, the second preset time interval and the first preset time interval may be the same or different and may be set according to actual needs.
[0080] In some embodiments of the present invention, in the process of uploading the incompletely uploaded portion of the file in pieces according to the second change relationship, the method further includes:
[0081] Get the maximum shard value;
[0082] If the target fragment value is greater than or equal to the maximum fragment value, the unfinished portion of the file is uploaded in fragments according to the maximum fragment value.
[0083] In this embodiment, when the target fragmentation value is continuously increased according to the second change relationship, when it increases to the maximum fragmentation value, the upload speed may decrease due to the continued increase in the target fragmentation value, because the increased network burden will lead to an increase in TCP retransmissions, and the larger the fragmentation value, the higher the probability of file upload failure. At this time, the adjustment of the target fragmentation value is stopped, and the unfinished part of the file is fixedly uploaded with the maximum fragmentation value until all fragments are uploaded. At this time, the growth of the target fragmentation value enters a stable growth stage from a slow growth stage.
[0084] As an example, the maximum fragment value is set to S max , when the second corresponding relationship of the previous stage is passed, for example, S = C × ln (S ′ +1), the determined target shard value exceeds S max When the S max The unfinished part of the file is uploaded in pieces. The change curve of the target shard value after the rapid growth stage A1, the slow growth stage A2, and the stable growth stage A3 can be shown as follows: Figure 2 shown.
[0085] In actual applications, the target score can also be dynamically adjusted based on the real-time network detection. For example, when detecting the network environment, if the network is good, the fragment size will be increased; if the network is extremely poor, the fragment size will be reduced. This dynamic adjustment mechanism can adjust the size of the uploaded fragment in time according to the network conditions, thereby improving the success rate of file upload.
[0086] In some embodiments of the present invention, before obtaining the initial fragmentation value, the method further includes:
[0087] Acquire first network environment data; wherein the first network environment data is network environment data corresponding to the first network connected by the client, and the network environment data includes one or more of the following: network connection type, network bandwidth information, and communication protocol information;
[0088] Determining a network environment indicator value of the first network according to the first network environment data;
[0089] The initial fragmentation value and the maximum fragmentation value are determined according to the network environment indicator value.
[0090] In this embodiment, since the network status is different and the pressure on the network is different in different network environments, the network environment index value is determined by the network environment data, and then the initial fragmentation value and the maximum fragmentation value are determined according to the network environment index value. This can make the fragmented upload of the file better adapt to the network environment and better utilize the network bandwidth.
[0091] As an example, when the network connection type of the first network currently connected by the client is obtained as 5G network, the network bandwidth is 1Gbps, etc., the first network environment index value is calculated based on these data by a preset algorithm. Then, the calculated first network environment index value reflects that the network environment of the first network is good, and a larger initial fragmentation value and a larger maximum fragmentation value can be set by configuring a mapping table or the like.
[0092] In actual applications, different initial fragmentation values and maximum fragmentation values may also be set only by different network connection types. For example, the initial fragmentation values and maximum fragmentation values corresponding to WIFI, 5G, 4G and other types of network connections may be set respectively.
[0093] In some embodiments of the present invention, the method further comprises:
[0094] In response to the operation of switching the network connection of the client, obtaining second network environment data; wherein the second network environment data is network environment data corresponding to the second network connected to the client after switching the network connection;
[0095] Determining a second network environment indicator value of the second network according to the second network environment data;
[0096] The initial fragmentation value and the maximum fragmentation value are re-determined according to the second network environment indicator value.
[0097] In this embodiment, when the network connection of the client changes, for example, switching from a WIFI connection to a 4G network, or from a 4G network to a 5G network, the original initial fragmentation value and the maximum fragmentation value become inapplicable.
[0098] In a specific implementation, after the initial fragmentation value and the maximum fragmentation value are re-determined by the second network environment indicator value, a new initial fragmentation value is needed to adjust the target fragmentation value. For example, the target fragmentation value is re-adjusted according to the three stages of rapid growth, slow growth, and stable growth.
[0099] In this way, it can adapt to different network environments. For example, the bandwidth in a WIFI environment may be relatively large. At a certain moment, the user switches to a 4G network. At this time, the bandwidth of the 4G network may be smaller than that of WIFI. The original target fragmentation value will cause congestion in the 4G network environment and the upload failure rate will increase. Therefore, the fragmentation size is adjusted to the initial fragmentation value in the 4G environment, and then the file is uploaded in fragments again according to the above three stages to ensure the upload success rate.
[0100] In actual applications, when a file fails to be uploaded in pieces, a retransmission mechanism can be started. During retransmission, the initial fragment value is set to the initial fragment value corresponding to the network environment currently connected to the client, and then the target fragment value is adaptively adjusted according to the three-stage structure until all fragments are uploaded. If the number of retransmissions exceeds a certain number, such as 5 times, it can be determined that the entire file upload has failed.
[0101] In some embodiments of the present invention, the method further comprises:
[0102] Save the uploaded data of each slice of the file; wherein the uploaded data includes one or more of the following: the target slice value corresponding to each slice, the sequence number corresponding to each slice, the size information of the file, and the unique identifier corresponding to each slice;
[0103] Determine whether there are shards that failed to be uploaded;
[0104] If there are segments that failed to be uploaded, the segments that failed to be uploaded are re-uploaded according to the uploaded data.
[0105] In this embodiment, during the process of uploading the file in pieces, the uploaded data of each piece can be saved to achieve breakpoint resume.
[0106] In the specific implementation, the redis database can be used to save the uploaded data of each shard, such as the shard size (that is, the target shard value when sharding), the shard sequence number, the file size information, the unique identifier corresponding to each shard (such as MD5 (Message-Digest Algorithm 5, fifth edition message digest algorithm) value), etc.
[0107] Since the target shard value is adjusted dynamically, it is necessary to record the target shard value each time so that the system can know the shards that have been successfully uploaded; the unique identifier can be used to verify whether each shard is consistent to prevent the shards from being tampered with during the upload process.
[0108] The data structure for saving data in redis can be as follows Figure 3 As shown:
[0109] The key can be a unique identifier of the file, such as the MD5 value; the total size of the file; the list of uploaded fragments, detail; the successful upload mark success; the detail contains the name (name), size (size), serial number (index) and other data of each fragment.
[0110] When each segment is uploaded, the segment data is recorded in detail. When all segments are uploaded, the success flag is updated, for example, set to Boolean true.
[0111] If there are fragments that failed to be uploaded, the system will find the fragment number of the file that was most recently uploaded but failed. You only need to upload the fragment corresponding to the fragment number.
[0112] In actual applications, the upload data can be saved in shards to achieve the function of instant upload. For example, if the same file is uploaded repeatedly, the system will compare its MD5 value with the MD5 value recorded in redis. If there is a successful upload mark, it is considered that the file has been uploaded successfully, and the file can be uploaded in seconds.
[0113] In actual applications, when all shards are uploaded successfully, a merge request needs to be initiated to the server that receives the file. The server can merge shards according to the shard sequence number based on the uploaded data of the saved shards. When merging shards, a stream merge method can be used, that is, each shard is converted into a data stream and then merged. The data in the data stream does not need to be loaded into the memory all at once, and the memory occupied is smaller than other merge methods, which can improve the efficiency of shard merging.
[0114] Step 106: Feedback the upload result of the file.
[0115] In step 106, if all segments of the file are uploaded successfully, a response indicating successful upload may be fed back; otherwise, a response indicating failed upload may be fed back.
[0116] In some examples, for ease of understanding, the implementation process of uploading files in pieces can be as follows: Figure 4 The implementation process is as follows:
[0117] First, the initial fragmentation value is used as the target score, and the file is uploaded in fragments. This is the rapid growth (also called fast start) stage, and the first change relationship is S = 2 × S'; then, when it is detected that the network response speed parameter value does not meet the preset threshold, the adjustment strategy of the target fragmentation value is changed, and the second change relationship S = C × ln (S ′ +1) is adjusted, which is the slow growth stage; when the target shard value grows to the maximum shard value through the second change relationship, the target shard value is stopped from being adjusted, and the fixed S=S max Upload the unfinished part of the file in multiple parts.
[0118] When all the segments of the file are uploaded successfully, the server is notified to merge the segments; if the upload fails, a retransmission mechanism is initiated to re-upload the file in segments according to the above process.
[0119] The embodiment of the present invention has the following advantages: by responding to a request to upload a file, an initial fragmentation value and a first change relationship are obtained, wherein the first change relationship represents that the target fragmentation value of the file increases at a preset rate as time increases, and the file is uploaded in pieces according to the initial fragmentation value and the first change relationship. In the process of uploading the file in pieces according to the initial fragmentation value and the first change relationship, a network response speed parameter value is obtained. If the network response speed parameter value does not meet the preset threshold, a second change relationship is obtained, wherein the second change relationship represents that the target fragmentation value increases as time increases, and the rate of change of the target fragmentation value decreases as time increases. According to the second change relationship, the part of the file that has not been uploaded is uploaded in pieces, and the upload result of the file is fed back, thereby realizing dynamic adjustment of the target fragmentation value, so that the piecewise uploading of the file can adapt to the complex and changeable network environment, which not only improves the efficiency of file uploading, but also improves the stability of file uploading.
[0120] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0121] Reference Figure 5 , shows a schematic diagram of the structure of a file processing device provided by an embodiment of the present invention, which may specifically include the following modules:
[0122] The initial sharding value and first change relationship acquisition module 501 is used to obtain the initial sharding value and the first change relationship in response to the request to upload the file; wherein the first change relationship indicates that the target sharding value of the file increases at a preset rate as time increases;
[0123] A first segment uploading module 502, configured to upload the file in segments according to the initial segment value and the first change relationship;
[0124] A response speed parameter value acquisition module 503, used for acquiring a network response speed parameter value in the process of uploading the file in pieces according to the initial piece value and the first change relationship;
[0125] A second change relationship acquisition module 504 is used to acquire a second change relationship if the network response speed parameter value does not meet the preset threshold; wherein the second change relationship indicates that the target shard value increases with time, and the change rate of the target shard value decreases with time;
[0126] A second segment uploading module 505, configured to perform segment uploading of the incompletely uploaded portion of the file according to the second change relationship;
[0127] The upload result feedback module 506 is used to feedback the upload result of the file.
[0128] In some embodiments of the present invention, the apparatus further comprises:
[0129] The third segmented uploading module is configured to, during the process of segmentally uploading the unuploaded portion of the file according to the second change relationship:
[0130] Get the maximum shard value;
[0131] If the target fragment value is greater than or equal to the maximum fragment value, the unfinished portion of the file is uploaded in fragments according to the maximum fragment value.
[0132] In some embodiments of the present invention, the apparatus further comprises:
[0133] A first network environment data acquisition module is used to acquire first network environment data; wherein the first network environment data is network environment data corresponding to the first network connected by the client, and the network environment data includes one or more of the following: network connection type, network bandwidth information, and communication protocol information;
[0134] A network environment indicator value acquisition module, used to determine the network environment indicator value of the first network according to the first network environment data;
[0135] The initial fragmentation value and the maximum fragmentation value determination module is used to determine the initial fragmentation value and the maximum fragmentation value according to the network environment indicator value.
[0136] In some embodiments of the present invention, the first segment uploading module 502 includes:
[0137] The first fragment upload submodule is used to upload the file in fragments using the initial fragment value as the target fragment value, and increase the target fragment value according to the first change relationship at a first preset time interval; wherein, in adjacent time intervals, the target fragment value of the latter time interval is a preset multiple of the target fragment value of the previous time interval.
[0138] In some embodiments of the present invention, the second change relationship is a logarithmic function relationship, and the logarithmic function relationship also includes a preset constant. The second segment uploading module 505 includes:
[0139] a target shard value determination submodule, configured to determine the target shard value according to the second change relationship, and upload the unuploaded portion of the file in segments according to the target shard value;
[0140] The target sharding value adjustment module is used to increase the target sharding value according to the second corresponding relationship at a second preset time interval; wherein, in adjacent time intervals, the target sharding value of the latter time interval and the target sharding value of the previous time interval satisfy the logarithmic function relationship.
[0141] The device also includes:
[0142] A second network environment data acquisition module, configured to acquire second network environment data in response to the operation of the client switching the network connection; wherein the second network environment data is the network environment data corresponding to the second network connected to the client after the network connection is switched;
[0143] A second network environment indicator value determination module, used to determine a second network environment indicator value of the second network according to the second network environment data;
[0144] The initial fragmentation value and the maximum fragmentation value resetting module is used to re-determine the initial fragmentation value and the maximum fragmentation value according to the second network environment indicator value.
[0145] In some embodiments of the present invention, the apparatus further comprises:
[0146] An upload data saving module, used to save the upload data of each slice of the file; wherein the upload data includes one or more of the following: the target slice value corresponding to each slice, the sequence number corresponding to each slice, the size information of the file, and the unique identifier corresponding to each slice;
[0147] The upload judgment module is used to judge whether there are fragments that failed to be uploaded;
[0148] The retransmission module is used to re-upload the fragments that failed to be uploaded according to the uploaded data if there are any fragments that failed to be uploaded.
[0149] Some embodiments of the present invention further provide an electronic device, which may include a processor, a memory, and a computer program stored in the memory and capable of running on the processor, and the computer program implements the above file processing method when executed by the processor.
[0150] Some embodiments of the present invention further provide a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the above file processing method is implemented.
[0151] Some embodiments of the present invention further provide a computer program product, including a computer program, which implements the above file processing method when executed by a processor.
[0152] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0153] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0154] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0155] Those skilled in the art will appreciate that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0156] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0157] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0158] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0159] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0160] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the above elements.
[0161] The provided file processing method and device, electronic device, and storage medium are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A method for file processing, characterized in that: The method comprises: In response to a request to upload a file, an initial shard value and a first change relationship are obtained; wherein the first change relationship indicates that the target shard value of the file increases at a preset rate as time increases; Uploading the file in pieces according to the initial piece value and the first change relationship; In the process of uploading the file in pieces according to the initial piece value and the first change relationship, obtaining a network response speed parameter value; If the network response speed parameter value does not meet the preset threshold, a second change relationship is obtained; wherein the second change relationship indicates that the target shard value increases with time, and the change rate of the target shard value decreases with time; According to the second change relationship, uploading the unfinished portion of the file in segments; Feedback the upload result of the file.
2. The method according to claim 1, characterized in that In the process of uploading the incompletely uploaded portion of the file in pieces according to the second change relationship, the method further includes: Get the maximum shard value; If the target fragment value is greater than or equal to the maximum fragment value, the unfinished portion of the file is uploaded in fragments according to the maximum fragment value.
3. The method according to claim 2, characterized in that Before obtaining the initial fragmentation value, the method further includes: Acquire first network environment data; wherein the first network environment data is network environment data corresponding to the first network connected by the client, and the network environment data includes one or more of the following: network connection type, network bandwidth information, and communication protocol information; Determining a network environment indicator value of the first network according to the first network environment data; The initial fragmentation value and the maximum fragmentation value are determined according to the network environment indicator value.
4. The method according to any one of claims 1 to 3, characterized in that: The uploading the file in pieces according to the initial piece value and the first change relationship includes: The file is uploaded in segments using the initial segment value as the target segment value, and the target segment value is increased according to the first change relationship at a first preset time interval; wherein, in adjacent time intervals, the target segment value of the latter time interval is a preset multiple of the target segment value of the previous time interval.
5. The method according to any one of claims 1 to 3, characterized in that: The second change relationship is a logarithmic function relationship, and the logarithmic function relationship also includes a preset constant. The uploading of the unuploaded portion of the file in pieces according to the second change relationship includes: Determine the target fragmentation value according to the second change relationship, and upload the unfinished portion of the file in fragments according to the target fragmentation value; At a second preset time interval, the target sharding value is increased according to the second corresponding relationship; wherein, in adjacent time intervals, the target sharding value of the latter time interval and the target sharding value of the previous time interval satisfy the logarithmic function relationship.
6. The method according to claim 3, characterized in that The method further comprises: In response to the operation of switching the network connection of the client, obtaining second network environment data; wherein the second network environment data is the network environment data corresponding to the second network connected to the client after switching the network connection; Determining a second network environment indicator value of the second network according to the second network environment data; The initial fragmentation value and the maximum fragmentation value are re-determined according to the second network environment indicator value.
7. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Save the uploaded data of each slice of the file; wherein the uploaded data includes one or more of the following: the target slice value corresponding to each slice, the sequence number corresponding to each slice, the size information of the file, and the unique identifier corresponding to each slice; Determine whether there are shards that failed to be uploaded; If there are segments that failed to be uploaded, the segments that failed to be uploaded are re-uploaded according to the uploaded data.
8. A file processing device, characterized in that: The device comprises: An initial sharding value and first change relationship acquisition module, used to obtain an initial sharding value and a first change relationship in response to a request to upload a file; wherein the first change relationship indicates that the target sharding value of the file increases at a preset rate as time increases; A first fragment uploading module, used for uploading the file in fragments according to the initial fragment value and the first change relationship; A response speed parameter value acquisition module, used for acquiring a network response speed parameter value in the process of uploading the file in pieces according to the initial piece value and the first change relationship; A second change relationship acquisition module, configured to acquire a second change relationship if the network response speed parameter value does not meet a preset threshold; wherein the second change relationship indicates that the target shard value increases with time, and the change rate of the target shard value decreases with time; A second piecewise uploading module, configured to upload the unuploaded portion of the file in pieces according to the second change relationship; The upload result feedback module is used to feedback the upload result of the file.
9. An electronic device, characterized in that: The invention comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the file processing method according to any one of claims 1 to 7 when executed by the processor.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the file processing method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
File dynamic fragmentation transmission method and device, equipment and storage medium
CN113765945A
File uploading method and system, client device and server
CN115529307A
File fragment transmission method and client
CN117729195A
Streaming media resource downloading method and apparatus, and terminal device
WO2016149863A1
Data transmission method, data transmission system, device and storage medium
WO2021189957A1