File uploading method, device and computer equipment
Through chunked uploading and synchronization of signature information, combined with chunk size and concurrency adjustment, the problem of long time-consuming traditional file uploads is solved and the efficiency and stability of file uploads are improved.
Patent Information
- Application Number
- CN202010529125.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-11
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2040-06-11
AI Technical Summary
The traditional file upload method has the problem that uploading takes a long time, especially when uploading large files, it takes a long time and affects the user experience.
By obtaining the file size, when the file size exceeds the threshold, it uses chunked upload and synchronously calculates the file signature information, sends the signature information to the server, receives the detection results, and adjusts the chunk size and concurrency number based on the detection results to optimize the upload process.
It reduces the time required to upload files, improves upload stability and success rate, and reduces user waiting time.
Smart Images

Figure CN113810433B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a file uploading method, device, computer equipment and storage medium. Background Art
[0002] Traditional file upload is implemented by uploading the file as a whole or in blocks. When the file size is small, the file is uploaded as a whole; when the file size is large, the file is uploaded in blocks to obtain file blocks. When all file blocks are uploaded, the corresponding computer device will splice the file blocks into a file. However, the current file upload method still has the problem of long upload time. Summary of the invention
[0003] Based on this, it is necessary to provide a file uploading method, apparatus, computer equipment and storage medium that can reduce the time consumption of file uploading in response to the above technical problems.
[0004] A file uploading method, the method comprising:
[0005] Get the file to be uploaded and the corresponding file size;
[0006] When the file size exceeds the file size threshold, the file to be uploaded is processed in blocks according to a preset block parameter value and uploaded, and the file signature information of the file to be uploaded is calculated synchronously;
[0007] Sending the file signature information to the server;
[0008] Receiving a detection result of the file signature information returned by the server;
[0009] When the received detection result is that the file signature information is not detected, the target file is processed in blocks and uploaded according to a preset transmission adjustment rule, wherein the target file includes files to be uploaded in addition to the uploaded file blocks, and the uploaded file blocks are file blocks that have been uploaded after the files to be uploaded have been processed in blocks.
[0010] A file uploading device, the device comprising:
[0011] The acquisition module is used to obtain the file to be uploaded and the corresponding file size;
[0012] A first block processing module, configured to, when the file size exceeds a file size threshold, perform block processing on the file to be uploaded according to a preset block parameter value and upload the file, and simultaneously calculate file signature information of the file to be uploaded;
[0013] A sending module, used for sending the file signature information to the server;
[0014] A receiving module, used for receiving the detection result of the file signature information returned by the server;
[0015] The second block processing module is used to block process and upload the target file according to the preset transmission adjustment rule when the received detection result is that the file signature information is not detected, wherein the target file includes the file to be uploaded in addition to the uploaded file block, and the uploaded file block is the file block that has been uploaded after the block processing of the file to be uploaded.
[0016] In one of the embodiments, the second block processing module is used to obtain the first file block from the target file, upload the first file block, and determine the upload time value of the first file block; when the upload time value reaches a first time threshold, reduce the block size to obtain the first block size; block the remaining files in the target file except the first file block according to the first block size to obtain the second file block, and upload the second file block.
[0017] In one embodiment, the second block processing module is used to reduce the upload concurrency number to obtain the first concurrency number when the first block size reaches the first block size threshold, and upload the second file block according to the first concurrency number.
[0018] In one of the embodiments, the second block processing module is used to reduce the block size according to the first block reduction value when the upload time value reaches a first time threshold and does not exceed a second time threshold, wherein the second time threshold is greater than the first time threshold; when the upload time value reaches the second time threshold, reduce the block size according to the second block reduction value, wherein the absolute value of the second block reduction value is greater than the absolute value of the first block reduction value.
[0019] In one of the embodiments, the second block processing module is used to obtain the first file block from the target file, upload the first file block, and determine the upload time value of the first file block; when the upload time value is lower than the first time threshold, increase the upload concurrency number to obtain the second concurrency number; perform block processing on the remaining files in the target file except the first file block to obtain the second file block, and upload the second file block according to the second concurrency number.
[0020] In one of the embodiments, the second block processing module is used to increase the block size to obtain a second block size when the second concurrency number reaches the upper limit of the concurrency number; block processing is performed on the target file to obtain a second file block, including: block processing is performed on the remaining files in the target file except the first file block according to the second block size to obtain a second file block.
[0021] In one embodiment, the sending module is used to send an interface call request to the server. The second block processing module is used to process and upload the target file in blocks according to a preset upload adjustment rule when the response time of the interface call request exceeds a preset time.
[0022] In one of the embodiments, the second block processing module is used to, when the received detection result is that the file signature information has been detected, receive the file path corresponding to the file to be uploaded returned by the server, and stop block processing of the target file.
[0023] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0024] Get the file to be uploaded and the corresponding file size;
[0025] When the file size exceeds the file size threshold, the file to be uploaded is processed in blocks according to a preset block parameter value and uploaded, and the file signature information of the file to be uploaded is calculated synchronously;
[0026] Sending the file signature information to the server;
[0027] Receiving a detection result of the file signature information returned by the server;
[0028] When the received detection result is that the file signature information is not detected, the target file is processed in blocks and uploaded according to a preset transmission adjustment rule, wherein the target file includes files to be uploaded in addition to the uploaded file blocks, and the uploaded file blocks are file blocks that have been uploaded after the files to be uploaded have been processed in blocks.
[0029] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:
[0030] Get the file to be uploaded and the corresponding file size;
[0031] When the file size exceeds the file size threshold, the file to be uploaded is processed in blocks according to a preset block parameter value and uploaded, and the file signature information of the file to be uploaded is calculated synchronously;
[0032] Sending the file signature information to the server;
[0033] Receiving a detection result of the file signature information returned by the server;
[0034] When the received detection result is that the file signature information is not detected, the target file is processed in blocks and uploaded according to a preset transmission adjustment rule, wherein the target file includes files to be uploaded in addition to the uploaded file blocks, and the uploaded file blocks are file blocks that have been uploaded after the files to be uploaded have been processed in blocks.
[0035] The above-mentioned file uploading method, device, computer equipment and storage medium obtain the file to be uploaded and the corresponding file size. When the file size exceeds the file size threshold, the file to be uploaded is processed in blocks according to the preset block parameter value and uploaded, and the file signature information of the file to be uploaded is calculated synchronously. The file signature can also be calculated when the file is uploaded, thereby reducing the time consumption of file uploading; the file signature information is sent to the server, and the detection result of the file signature information returned by the server is received. When the received detection result is that the file signature information is not detected, the target file is processed in blocks according to the preset transmission adjustment rule and uploaded, wherein the target file includes the file to be uploaded except the uploaded file block, and the uploaded file block is the file block after the file to be uploaded is processed in blocks and uploaded, and the target file can be adjusted to improve the stability of the upload and ensure the success rate of the file upload. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 An application environment diagram of a file uploading method in an embodiment;
[0037] Figure 2 A schematic diagram of a process of uploading a file in one embodiment;
[0038] Figure 3 A flowchart of a file uploading method in another embodiment;
[0039] Figure 4 It is a structural block diagram of a file uploading device in one embodiment;
[0040] Figure 5 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0042] The file upload method provided by this application can be applied to Figure 1In the application environment shown in FIG. 1 , the terminal 102 communicates with the server 104 through a network. The terminal 102 may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices, and the server 104 may be implemented by an independent server or a server cluster composed of multiple servers. The client is applied to the terminal 102, and the server is applied to the server 104.
[0043] In one embodiment, Figure 2 As shown, a file upload method is provided, which is applied to Figure 1 The terminal in the example, that is, the client, is used as an example to illustrate, including the following steps:
[0044] Step 202, obtaining the file to be uploaded and the corresponding file size.
[0045] The file to be uploaded may be a video file, an application package, a text document, etc., but is not limited thereto. The file size corresponding to the file to be uploaded may be, for example, 1MB (Mbyte, megabyte), 1500KB (Kilobyte, kilobyte), etc., but is not limited thereto.
[0046] Specifically, the client obtains a file upload instruction, and obtains the file to be uploaded and the file size corresponding to the file to be uploaded according to the file upload instruction.
[0047] Step 204: when the file size exceeds the file size threshold, the file to be uploaded is processed in blocks according to a preset block parameter value and uploaded, and the file signature information of the file to be uploaded is calculated synchronously.
[0048] Among them, the file size threshold is used to measure whether the file to be uploaded needs to be uploaded in blocks. The file size threshold is set on the client and can be configured according to needs. The preset block parameter value includes the preset block size, and can also include the number of concurrent uploads each time, but is not limited to this. The file signature information can be determined by the hash value of the file. Each file has corresponding file signature information, and the file signature information of each file is different. Block processing refers to the process in which the client divides the file to be transmitted into at least two file blocks, and then uploads each file block to the server.
[0049] Specifically, when the file size exceeds the file size threshold, it means that it is necessary to use the file block upload method. Then the client processes the uploaded file in blocks according to the preset block parameter value and uploads it. At this time, a certain time difference is allowed between the client's block processing and uploading. In general, the speed of block processing is greater than the upload speed. For example, the client has divided 10 file blocks at this time, but only uploaded 8 file blocks at this time. While the client processes the uploaded file in blocks according to the preset block parameter value and uploads it, it simultaneously calculates the file signature information of the file to be uploaded.
[0050] Step 206: Send the file signature information to the server.
[0051] Specifically, the client calls the second transfer interface to send the file signature information to the server. During the sending process, the client continues to process and transmit the uploaded file in blocks according to the preset block parameter value.
[0052] Step 208: Receive the detection result of the file signature information returned by the server.
[0053] Specifically, the server detects whether the same file signature information exists based on the file signature information, and returns the detection result of the file signature information to the client. The client interface returns the detection result of the file signature information to the server. The detection result may be that the file signature information is not detected, or that the file signature information has been detected.
[0054] Step 210, when the received detection result is that the file signature information is not detected, the target file is processed in blocks and uploaded according to the preset upload adjustment rules, wherein the target file includes the file to be uploaded in addition to the uploaded file block, and the uploaded file block is the file block that has been uploaded after the file to be uploaded is processed in blocks.
[0055] The preset upload adjustment rule may include at least one of a concurrent number adjustment rule and a block size adjustment rule. The concurrent number adjustment rule is used to adjust the number of file blocks uploaded simultaneously. The block size is used to adjust the size of the file block.
[0056] Specifically, when the detection result received by the client is that the file signature information is not detected, it means that there is no identical file on the server side, then the client divides the target file into blocks and uploads it according to the preset upload adjustment rules. The target file includes files to be uploaded in addition to the uploaded file blocks. The uploaded file blocks are file blocks that have been uploaded after the files to be uploaded have been divided into blocks. For example, the file to be transmitted includes file block A and file block B. While calculating the signature information of the file to be uploaded, the client has divided the blocks according to the preset dividing parameter value and uploaded file block A, then the remaining target file only contains file block B. Then the client re-divides the target file containing file block B into blocks and uploads it according to the preset transmission adjustment rules.
[0057] The above-mentioned file uploading method obtains the file to be uploaded and the corresponding file size. When the file size exceeds the file size threshold, the file to be uploaded is processed in blocks according to the preset block parameter value and uploaded, and the file signature information of the file to be uploaded is calculated synchronously. The file signature can also be calculated when uploading the file, thereby reducing the time consumption of file uploading; the file signature information is sent to the server, and the detection result of the file signature information returned by the server is received. When the received detection result is that the file signature information is not detected, the target file is processed in blocks according to the preset transmission adjustment rule and uploaded, wherein the target file includes the file to be uploaded except the uploaded file block, and the uploaded file block is the file block after the file to be uploaded is processed in blocks and uploaded, and the target file can be adjusted to improve the stability of the upload and ensure the success rate of the file upload.
[0058] In one embodiment, the traditional method adopts the method of calculating the file signature information first, and the client sends the file signature information to the server, and the server determines whether the server has a file with the same signature based on the file signature information. If there is no file with the same signature, the file is uploaded as a whole or in blocks. That is, the file signature and file upload are serial methods. However, this method will make the upload time longer, that is, the user's waiting time is long. However, the present application adopts the method of calculating the file signature information, processing the uploaded file in blocks and uploading it simultaneously. When the received detection result is that the file signature information has been detected, the traffic and server resources consumed by the uploaded file block will be wasted. However, due to the nature of the business, the probability of users uploading the same file is small, that is, the probability that the detection result is that the file signature information has been detected is small. In order to avoid a low-probability event, the benefit of increasing the length of the entire file upload is not high, so the present application adopts the method of calculating the file signature information, processing the uploaded file in blocks and uploading it in parallel. When the file signature information is calculated, the server-side second transmission interface is called separately to determine whether the file already exists. If so, the ongoing block upload is canceled. The method of the present application can reduce the time consumption of file upload.
[0059] In one embodiment, the target file is processed into blocks and uploaded according to a preset transmission adjustment rule, including: obtaining a first file block from the target file, uploading the first file block, and determining an upload time value of the first file block; when the upload time value reaches a first time threshold, reducing the block size to obtain a first block size; processing the remaining files in the target file except the first file block into blocks according to the first block size to obtain a second file block, and uploading the second file block.
[0060] Among them, the first time-consuming threshold can be used to measure the current network speed. When the first time-consuming threshold is reached, it means that the current network environment is poor and the network speed is low. Reaching can be greater than or equal to. Other files in the target file except the first file block, for example, the target file may include the first file block and the second file block, then in addition to the first file block, only the second file block is left. Reducing the block size can be reduced according to the block reduction value, for example, the second block size S2 = S1-D, where S1 is the block size of the first file block, D is the block reduction value, etc., not limited to this. In this embodiment, the block size of the first file block is greater than the first block size threshold.
[0061] Specifically, the client obtains the first file block from the target file, uploads the first file block, and determines the upload time value of the first file block. That is, the client first needs to process the target file into blocks to obtain the first file block, and upload the first file block, so as to determine the upload time value of the first file block. When the upload time value reaches the first time threshold, the block size is reduced to obtain the first block size. The client processes the remaining files in the target file except the first file block according to the first block size, obtains the second file block of the first block size, and uploads the second file block.
[0062] In this embodiment, the relationship between the first file block and the second file block is a sequential relationship. For example, the remaining files in the target file except the first file block are processed in blocks according to the first block size to obtain the second file block, and the second file block is uploaded. The upload time value of the second file block is determined, and when the upload time value reaches the first time threshold, the block size is reduced... Therefore, the second file block can also be the first file block in this embodiment, and the upload time value of the second file block is determined, so as to adjust the subsequent block size.
[0063] The above-mentioned file uploading method obtains the first file block from the target file, uploads the first file block, determines the upload time value of the first file block, and can reflect the current network situation through the upload time value. When the upload time value reaches the first time threshold, the block size is reduced to obtain the first block size, and the remaining files in the target file except the first file block are processed in blocks according to the first block size to obtain the second file block, and the second file block is transmitted. In the case of poor network environment, the block size can be reduced and the success rate of file upload can be improved.
[0064] In one embodiment, the file uploading method further includes: when the first block size reaches the first block size threshold, reducing the upload concurrency number to obtain the first concurrency number. Uploading the second file block includes: uploading the second file block according to the first concurrency number.
[0065] The first block size threshold may be a lower limit of the block size. The upload concurrency number refers to the number of file blocks uploaded by the client at the same time. The client may increase or decrease the concurrency number by controlling the number of interface call requests sent.
[0066] Specifically, when the first block size reaches the first block size threshold, that is, when the block size is reduced to the first block size threshold, the client reduces the upload concurrency number to obtain the first concurrency number. The client uploads the second file block according to the first concurrency number. For example, the original upload concurrency number is 10, that is, 10 file blocks are uploaded together. Then, the upload concurrency number is reduced, and the first concurrency number obtained may be 9.
[0067] In this embodiment, after uploading the second file block according to the first concurrency number, the transmission time consumption value of the second file block is obtained. When the transmission time consumption value still exceeds the first time consumption threshold and the first block size reaches the first block size threshold, the upload concurrency number continues to be reduced until the upload concurrency number reaches the minimum upload value or the transmission time consumption value is lower than the first time consumption threshold, and the upload concurrency number is stopped from being reduced.
[0068] In the above-mentioned file uploading method, when the first block size reaches the first block size threshold, that is, the block size can no longer be reduced, the upload concurrency number is reduced to obtain the first concurrency number, and the second file block is uploaded according to the first concurrency number. This method can reduce the upload concurrency number when the network condition is poor, thereby improving the success rate of file upload and reducing the load on the server.
[0069] In one embodiment, the target file is processed and uploaded in blocks according to a preset transmission adjustment rule, including: obtaining a first file block from the target file, uploading the first file block, and determining an upload time value of the first file block; when the upload time value reaches a first time threshold, reducing the upload concurrency number to obtain a first concurrency number; when the first concurrency number reaches a lower limit of the concurrency number, reducing the block size to obtain a first block size, processing the remaining files in the target file except the first file block in blocks according to the first block size, and uploading the second file block according to the first concurrency number.
[0070] In one embodiment, when the upload time value exceeds a first time threshold, the block size is reduced, including: when the upload time value reaches the first time threshold and does not exceed the second time threshold, the block size is reduced according to the first block reduction value, wherein the second time threshold is greater than the first time threshold; when the upload time value reaches the second time threshold, the block size is reduced according to the second block reduction value, wherein the absolute value of the second block reduction value is greater than the absolute value of the first block reduction value.
[0071] The block reduction value may be considered as having a negative sign or a positive sign. The absolute value of the second block reduction value is greater than the absolute value of the first block reduction value. For example, the second block reduction value may be -6, and the first block reduction value may be -3, then |-6|>|-3|.
[0072] Specifically, when the upload time value reaches the first time threshold and does not exceed the second time threshold, that is, the time threshold is within a certain range, the client can reduce the block size of the first file block according to the first block reduction value. When the upload time value reaches the second time threshold, that is, the upload time value is larger at this time, the block size is reduced according to the second block reduction value. For example, when the upload time value T exceeds the first time threshold T1 and does not exceed the second time threshold T2, the block size is reduced according to the first block reduction value D, that is, the second block size S2 = S1-D, where S1 is the block size of the first file block. When the upload time value T exceeds the second time threshold T2, the second block reduction value can be 2D, then, the block size of the first file block is reduced according to the second block reduction value 2D, and the second block size is S2 = S1-2D.
[0073] In the above-mentioned file uploading method, when the upload time value reaches the first time consumption threshold and does not exceed the second time consumption threshold, the block size is reduced according to the first block reduction value; when the upload time value exceeds the second time consumption value, the block size is reduced according to the second block reduction value, and the absolute value of the second block reduction value is greater than the absolute value of the first block reduction value, that is, when the upload time value is within a certain range, the reduction value is smaller, and when the upload time value is larger, the reduction value is larger, which can improve the file adjustment efficiency and is more in line with the network environment.
[0074] In one embodiment, the target file is processed in blocks and uploaded according to a preset transmission adjustment rule, including: obtaining a first file block from the target file, uploading the first file block, and determining an upload time value of the first file block; when the upload time value is lower than a first time threshold, increasing the upload concurrency number to obtain a second concurrency number; processing the remaining files in the target file except the first file block in blocks to obtain a second file block, and uploading the second file block according to the second concurrency number.
[0075] The first time-consuming threshold can be used to measure the current network speed. When it is lower than the first time-consuming threshold, it means that the current network environment is good and the network speed is fast. The increase in the number of concurrent connections can be increased according to the increase value, for example, the second concurrent connection number Y2=Y1+E, where Y1 is the block size of the first block, and E is the increase value, etc., and is not limited thereto.
[0076] Specifically, the client obtains the first file block from the target file, uploads the first file block, and determines the upload time value of the first file block. That is, the client first needs to process the target file into blocks to obtain the first file block, and upload the first file block, so as to determine the upload time value of the first file block. When the upload time value is lower than the first time threshold, the upload concurrency number is increased to obtain the second concurrency number. For example, the original upload concurrency number is 5, that is, 5 file blocks are uploaded together. Then increase the upload concurrency number, and the second concurrency number obtained can be 6. The client processes the remaining files in the target file except the first file block into blocks to obtain the second file block, and uploads the second file block according to the second concurrency number.
[0077] In this embodiment, the relationship between the first file block and the second file block is a sequential relationship. For example, the remaining files in the target file except the first file block are processed in blocks according to the first block size to obtain the second file block, and the second file block is uploaded. The upload time value of the second file block is determined, and when the upload time value reaches the first time threshold, the number of concurrent uploads is increased... Therefore, the second file block can also be the first file block in this embodiment, and the upload time value of the second file block is determined, so as to adjust the subsequent concurrent uploads.
[0078] The above-mentioned file uploading method obtains the first file block from the target file, uploads the first file block, determines the upload time value of the first file block, and can reflect the current network situation through the upload time value. When the upload time value is lower than the first time threshold, the upload concurrency number is increased to obtain the second concurrency number, and the remaining files in the target file except the first file block are processed in blocks to obtain the second file block. The second file block is transmitted according to the second concurrency number. The upload concurrency number can be increased when the network environment is good, thereby improving the utilization rate of the server interface.
[0079] In one embodiment, the file uploading method further includes: when the second concurrency number reaches the upper limit of the concurrency number, increasing the block size to obtain a second block size; processing the target file into blocks to obtain a second file block, including: processing the remaining files in the target file except the first file block into blocks according to the second block size to obtain a second file block.
[0080] The upper limit of the number of concurrent requests is determined by the number of currently callable interfaces. The upper limit of the number of concurrent requests is equal to the integer corresponding to the maximum number of requests under the same domain name supported by the server divided by the number of files being uploaded. For example, if the maximum number of requests is 101 and the number of files being uploaded is 10, then the upper limit of the number of concurrent requests is 10.
[0081] Specifically, when the second concurrency reaches the upper limit of the concurrency, the block size is increased to obtain a second block size. The client performs block processing on the remaining files in the target file except the first file block according to the second block size to obtain a second file block corresponding to the second block size. The second block size may be less than a second block size threshold. The second block size threshold is greater than the first block size threshold.
[0082] The above-mentioned file uploading method, when the second concurrency number reaches the upper limit of the concurrency number, increases the block size to obtain the second block size, and blocks the remaining files in the target file except the first file block according to the second block size to obtain the second file block. The block size can be increased in a poor network environment, the file upload time can be reduced, and the efficiency of file upload can be improved.
[0083] In one embodiment, the file uploading method further includes: sending an interface call request to the server; when the response time of the interface call request exceeds a preset time, executing the step of dividing the target file into blocks and uploading it according to a preset upload adjustment rule.
[0084] The preset duration can be set according to the requirements, for example, the preset duration can be 100 milliseconds, 10 milliseconds, etc., but is not limited thereto.
[0085] Specifically, the interface call request is used to request an interface from the server for uploading file blocks. The interface call request may also include a file identifier corresponding to the file to be transferred. The file identifier is composed of at least one of numbers, letters, text, and symbols. Each file to be transferred has a corresponding file identifier, and the file identifier of each file to be transferred is different. When the received detection result is that the file signature information is not detected, the client sends an interface call request to the server, and when the response time of the interface call request exceeds the preset time, the target file is processed in blocks and uploaded according to the preset upload adjustment rules.
[0086] The above-mentioned file upload method sends an interface call request to the server; when the response time of the interface call request exceeds the preset time, it means that the current network environment is poor, then the target file is processed in blocks and uploaded according to the preset upload adjustment rules, so as to ensure the stability of the block upload interface and improve the success rate of file upload.
[0087] In one embodiment, the file uploading method further includes: when the received detection result is that the file signature information has been detected, receiving the file path corresponding to the file to be uploaded returned by the server, and stopping the block processing of the target file.
[0088] Specifically, when the received detection result is that the file signature information has been detected, it means that the file to be transmitted already exists in the server. Then the server returns the file path corresponding to the file to be uploaded to the client. The server receives the file path corresponding to the file to be uploaded returned by the server and stops the block processing of the target file.
[0089] In the above-mentioned file uploading method, when the received detection result is that the file signature information has been detected, it means that the file to be transmitted already exists in the server, then the block processing of the target file is stopped, even though a part of the file to be transmitted has been uploaded, that is, a part of the file within the time corresponding to the calculation of the file signature information and the transmission file signature information, and the file to be transmitted already exists in the server, it will not actually increase the user's waiting time, but can reduce the user's waiting time when there is no identical file in the server.
[0090] In one embodiment, when transmitting a file block, the client simultaneously transmits the file block sequence number corresponding to the file block. When the upload of the file to be transmitted is completed, the server splices the uploaded file blocks into the file to be transmitted according to the file block sequence number.
[0091] In one embodiment, Figure 3 FIG. 1 is a flowchart of a method for uploading a file in another embodiment, comprising:
[0092] Step 302: The client obtains the file to be uploaded and the corresponding file upload instruction and file size.
[0093] Specifically, the file to be uploaded is obtained, and a start upload control in the client is triggered, that is, a file upload instruction is obtained. The client determines the file size of the file to be uploaded.
[0094] Step 304: the client requests the server to initiate file upload according to the file upload instruction, and the server determines the file identifier corresponding to the file to be uploaded.
[0095] Specifically, the client requests the server to initiate a file upload. When the server receives the file upload instruction, it determines the file identifier corresponding to the file to be uploaded. The file identifier is unique, and the file identifier of each file to be uploaded is different. In the subsequent file upload process, all network requests between the client and the server will carry the file identifier (uploadId) to identify the file to be uploaded. The server returns the file identifier to the client.
[0096] Step 306: The client determines whether the file size exceeds a file size threshold.
[0097] Specifically, after receiving the file identifier, the client determines whether the file size exceeds the file size threshold.
[0098] Step 308: If the file size does not exceed the file size threshold, the entire file is uploaded and the file signature information corresponding to the file to be uploaded is calculated.
[0099] Step 310: The client requests the server to determine whether the same file signature information already exists.
[0100] Specifically, the client requests the server interface to determine whether the server already has the same file signature information.
[0101] Step 312: If the same file signature information is not detected, the client initiates a request to upload the entire file.
[0102] Specifically, if the same file signature information has been detected, step 314 is executed.
[0103] Step 314, upload completed.
[0104] Specifically, the upload is completed when the block processing is completed. After the upload is completed, the client sends the file block sequence number and the corresponding file block signature information of each file block to the server, so that the server can verify the file block sequence number and the corresponding file block signature information uploaded by the client. When the verification is successful, the server will splice the uploaded file blocks into the file to be uploaded according to the file block sequence number and the file block signature information, and return the file path of the file to be uploaded. The upload process ends.
[0105] Step 316: If the file size exceeds the file size threshold, the file is uploaded in chunks, and the file signature information corresponding to the file to be uploaded is calculated.
[0106] Step 318, the file to be uploaded is divided into blocks and uploaded.
[0107] Wherein, step 316 and step 318 are executed simultaneously. If step 326 is executed first and then step 318 is executed, the file to be uploaded is processed in blocks according to at least one of the block size and the number of concurrent connections and uploaded. If step 318 is not executed after step 326 is executed, the file to be uploaded is processed in blocks according to the preset block parameter value and uploaded.
[0108] Specifically, after the client divides the file to be uploaded into blocks, it requests the server to use the block upload interface, which carries the file identifier of the file to be uploaded and the sorting number of the file block in the file. If the request is successful, the client can upload the file through the interface, and the server returns the file block signature information of the file block after receiving the request. The client temporarily saves the file block sequence number and signature information. If the interface call request initiated by the client fails and the number of retry requests is less than the number threshold, the interface call request is re-initiated. When the response time of the interface call request is longer than the preset time, at least one of the block size and the number of concurrency is adjusted according to the preset transmission adjustment rules, and the interface call request is re-initiated.
[0109] Step 320: The client requests the server to determine whether the same file signature information already exists.
[0110] Specifically, when the server determines that the same file signature information already exists, step 314 is executed and the upload is completed.
[0111] Step 322: If not, determine whether the block segmentation is completed?
[0112] Specifically, when the block division is completed, step 314 is executed and the uploading is completed.
[0113] Step 324: If the block is not finished, determine whether the time consumed by the block upload interface exceeds the first time consumption threshold?
[0114] Specifically, when the time consumed by the block upload interface does not exceed the first time consumption threshold, step 318 is continued to be executed, that is, block processing and uploading are performed according to the block size and concurrency number of the previous file block.
[0115] Step 326: When the block upload interface exceeds the first time-consuming threshold, at least one of the block size and the number of concurrent connections is determined.
[0116] The above-mentioned file uploading method obtains the file to be uploaded and the corresponding file size. When the file size exceeds the file size threshold, the file to be uploaded is processed in blocks according to the preset block parameter value and uploaded, and the file signature information of the file to be uploaded is calculated synchronously. The file signature can also be calculated when uploading the file, thereby reducing the time consumption of file uploading; the file signature information is sent to the server, and the detection result of the file signature information returned by the server is received. When the received detection result is that the file signature information is not detected, the target file is processed in blocks according to the preset transmission adjustment rule and uploaded, wherein the target file includes the file to be uploaded except the uploaded file block, and the uploaded file block is the file block after the file to be uploaded is processed in blocks and uploaded, and the target file can be adjusted to improve the stability of the upload and ensure the success rate of the file upload.
[0117] The present application also provides an application scenario, which applies the above-mentioned file upload method. Specifically, the application of the file upload method in this application scenario is as follows: obtain the video file to be uploaded and the corresponding file size; when the file size exceeds the file size threshold, the video file to be uploaded is processed and uploaded in blocks according to the preset block parameter value, and the file signature information of the video file to be uploaded is calculated synchronously; the file signature information is sent to the server; the detection result of the file signature information returned by the server is received; when the received detection result is that the file signature information is not detected, the target video file is processed and uploaded in blocks according to the preset transmission adjustment rules, wherein the target file includes the video file to be uploaded except the uploaded video file block, and the uploaded video file block is the file block after the video file to be uploaded is processed in blocks and uploaded. When the received detection result is that the file signature information has been detected, the file path corresponding to the video file to be uploaded returned by the receiving server is returned, and the block processing of the target video file is stopped.
[0118] It should be understood that although Figures 2 to 3 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figures 2 to 3 At least part of the steps may include multiple steps or multiple stages. These steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed in turn or alternately with other steps or at least part of the steps or stages in other steps.
[0119] In one embodiment, Figure 4As shown, a file uploading device is provided, which can adopt a software module or a hardware module, or a combination of the two to become a part of a computer device. The device specifically includes: an acquisition module 402, a first block processing module 404, a sending module 406, a receiving module 408 and a second block processing module 410, wherein:
[0120] The acquisition module 402 is used to acquire the file to be uploaded and the corresponding file size;
[0121] The first block processing module 404 is used to process the file to be uploaded in blocks according to a preset block parameter value and upload it when the file size exceeds the file size threshold, and simultaneously calculate the file signature information of the file to be uploaded;
[0122] The sending module 406 is used to send the file signature information to the server;
[0123] The receiving module 408 is used to receive the detection result of the file signature information returned by the server;
[0124] The second block processing module 410 is used to block process and upload the target file according to the preset transmission adjustment rule when the received detection result is that the file signature information is not detected, wherein the target file includes the file to be uploaded in addition to the uploaded file block, and the uploaded file block is the file block that has been uploaded after the block processing of the file to be uploaded.
[0125] The above-mentioned file uploading device obtains the file to be uploaded and the corresponding file size. When the file size exceeds the file size threshold, the file to be uploaded is processed in blocks according to the preset block parameter value and uploaded, and the file signature information of the file to be uploaded is calculated synchronously. The file signature can also be calculated when uploading the file, thereby reducing the time consumption of file uploading; the file signature information is sent to the server, and the detection result of the file signature information returned by the server is received. When the received detection result is that the file signature information is not detected, the target file is processed in blocks according to the preset transmission adjustment rule and uploaded, wherein the target file includes the file to be uploaded except the uploaded file block, and the uploaded file block is the file block after the file to be uploaded is processed in blocks and uploaded, and the target file can be adjusted to improve the stability of the upload and ensure the success rate of the file upload.
[0126] In one embodiment, the second block processing module 410 is used to obtain the first file block from the target file, upload the first file block, and determine the upload time value of the first file block; when the upload time value reaches the first time threshold, reduce the block size to obtain the first block size; block the remaining files in the target file except the first file block according to the first block size to obtain the second file block, and upload the second file block.
[0127] The above-mentioned file uploading device obtains the first file block from the target file, uploads the first file block, determines the upload time value of the first file block, and can reflect the current network situation through the upload time value. When the upload time value reaches the first time threshold, the block size is reduced to obtain the first block size, and the remaining files in the target file except the first file block are processed in blocks according to the first block size to obtain the second file block, and the second file block is transmitted. In the case of poor network environment, the block size can be reduced to improve the success rate of file uploading.
[0128] In one embodiment, the second block processing module 410 is used to reduce the upload concurrency number to obtain the first concurrency number when the first block size reaches the first block size threshold, and upload the second file block according to the first concurrency number.
[0129] The above-mentioned file uploading device, when the first block size reaches the first block size threshold, that is, the block size can no longer be reduced, reduces the upload concurrency number to obtain the first concurrency number, and uploads the second file block according to the first concurrency number. It can reduce the upload concurrency number when the network condition is not good, thereby improving the success rate of file upload and reducing the load on the server.
[0130] In one embodiment, the second block processing module 410 is used to reduce the block size according to the first block reduction value when the upload time value reaches the first time threshold and does not exceed the second time threshold, wherein the second time threshold is greater than the first time threshold; when the upload time value reaches the second time threshold, reduce the block size according to the second block reduction value, wherein the absolute value of the second block reduction value is greater than the absolute value of the first block reduction value.
[0131] The above-mentioned file uploading device reduces the block size according to the first block reduction value when the upload time value reaches the first time threshold and does not exceed the second time threshold. When the upload time value exceeds the second time value, the block size is reduced according to the second block reduction value. The absolute value of the second block reduction value is greater than the absolute value of the first block reduction value. That is, the reduction value is smaller when the upload time value is within a certain range, and the reduction value is larger when the upload time value is larger. This can improve the file adjustment efficiency and is more in line with the network environment.
[0132] In one embodiment, the second block processing module 410 is used to obtain the first file block from the target file, upload the first file block, and determine the upload time value of the first file block; when the upload time value is lower than the first time threshold, increase the upload concurrency number to obtain the second concurrency number; perform block processing on the remaining files in the target file except the first file block to obtain the second file block, and upload the second file block according to the second concurrency number.
[0133] The above-mentioned file uploading device obtains the first file block from the target file, uploads the first file block, determines the upload time value of the first file block, and can reflect the current network situation through the upload time value. When the upload time value is lower than the first time threshold, the upload concurrency number is increased to obtain the second concurrency number, and the remaining files in the target file except the first file block are processed in blocks to obtain the second file block. The second file block is transmitted according to the second concurrency number. The upload concurrency number can be increased when the network environment is good, thereby improving the utilization rate of the server interface.
[0134] In one embodiment, the second block processing module 410 is used to increase the block size to obtain a second block size when the second concurrency number reaches the upper limit of the concurrency number; block processing the target file to obtain a second file block, including: block processing the remaining files in the target file except the first file block according to the second block size to obtain a second file block.
[0135] The above-mentioned file uploading device increases the block size to obtain the second block size when the second concurrency number reaches the upper limit of the concurrency number, and blocks the remaining files in the target file except the first file block according to the second block size to obtain the second file block. The block size can be increased in a poor network environment, the file upload time can be reduced, and the efficiency of file upload can be improved.
[0136] In one embodiment, the sending module 406 is used to send an interface call request to the server. The second block processing module 410 is used to process and upload the target file in blocks according to a preset upload adjustment rule when the response time of the interface call request exceeds a preset time.
[0137] The above-mentioned file uploading device sends an interface call request to the server; when the response time of the interface call request exceeds the preset time, it means that the current network environment is poor, and then the target file is processed in blocks and uploaded according to the preset upload adjustment rules, thereby ensuring the stability of the block upload interface and improving the success rate of file upload.
[0138] In one embodiment, the second block processing module 410 is used to, when the received detection result is that the file signature information has been detected, receive the file path corresponding to the file to be uploaded returned by the server, and stop block processing of the target file.
[0139] The above-mentioned file uploading device, when the received detection result is that the file signature information has been detected, it means that the file to be transmitted already exists in the server, then the block processing of the target file is stopped, even though a part of the file to be transmitted has been uploaded, that is, a part of the file within the time corresponding to the calculation file signature information and the transmission file signature information, and the file to be transmitted already exists in the server, it will not actually increase the user's waiting time, but can reduce the user's waiting time when there is no identical file in the server.
[0140] For the specific definition of the file uploading device, please refer to the definition of the file uploading method above, which will not be repeated here. Each module in the above-mentioned file uploading device can be implemented in whole or in part by software, hardware and their combination. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0141] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, an operator network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a file upload method is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a button, a trackball or a touch pad set on the computer device housing, or an external keyboard, touch pad or mouse, etc.
[0142] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0143] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0144] In one embodiment, a computer-readable storage medium is provided, storing a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0145] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0146] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0147] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A file uploading method, characterized in that: The method comprises: Get the file to be uploaded and the corresponding file size; When the file size exceeds the file size threshold, the file to be uploaded is processed in blocks according to a preset block parameter value and uploaded, and the file signature information of the file to be uploaded is calculated synchronously; Sending the file signature information to the server; Receiving a detection result of the file signature information returned by the server; When the received detection result is that the file signature information is not detected, sending an interface call request to the server; When the response time of the interface call request exceeds a preset time, a first file block is obtained from the target file, the first file block is uploaded, and a time consumption value for uploading the first file block is determined; the target file includes files to be uploaded except the uploaded file blocks, and the uploaded file blocks are file blocks that have been uploaded after the files to be uploaded are divided into blocks; When the upload time value reaches a first time threshold, reducing the block size to obtain a first block size, dividing the remaining files in the target file except the first file block into blocks according to the first block size to obtain a second file block, and uploading the second file block; When the upload time value is lower than the first time threshold, the upload concurrency number is increased to obtain a second concurrency number, the remaining files in the target file except the first file block are divided into blocks to obtain second file blocks, and the second file blocks are uploaded according to the second concurrency number.
2. The method according to claim 1, characterized in that The sending of the interface call request to the server includes: Sending an interface call request carrying the file identifier of the file to be uploaded and the file block sequence number of the file block to be uploaded in the file to be uploaded to the server, so that the server stores the file block sequence number of the file block to be uploaded and returns the file block signature information of the file block to be uploaded; The file block sequence number and file block signature information of the file block to be uploaded are cached.
3. The method according to claim 2, characterized in that The method further comprises: After all file blocks of the file to be uploaded are uploaded, the file block sequence number and the corresponding file block signature information of each file block are sent to the server, so that the server verifies the file block sequence number and the corresponding file block signature information. After the verification is successful, the uploaded file blocks are spliced according to the file block sequence number and the corresponding file block signature information to obtain the file to be uploaded, and the file path of the file to be uploaded is returned.
4. The method according to claim 1, characterized in that: The method further comprises: When the first block size reaches a first block size threshold, reducing the number of concurrent uploads to obtain a first concurrent number; The uploading of the second file block includes: The second file block is uploaded according to the first concurrent number.
5. The method according to claim 4, characterized in that The method further comprises: After uploading the second file block according to the first concurrent number, obtaining a transmission time consumption value of the second file block; When the transmission time value exceeds the first time threshold and the first block size reaches the first block size threshold, continue to reduce the number of concurrent uploads until the number of concurrent uploads reaches the lower limit of the number of concurrent uploads or the transmission time value is lower than the first time threshold, and stop reducing the number of concurrent uploads.
6. The method according to claim 1, characterized in that When the upload time value exceeds a first time threshold, reducing the block size includes: When the upload time value reaches a first time threshold and does not exceed a second time threshold, reducing the block size according to a first block reduction value, wherein the second time threshold is greater than the first time threshold; When the upload time value reaches the second time threshold, the block size is reduced according to a second block reduction value, wherein an absolute value of the second block reduction value is greater than an absolute value of the first block reduction value.
7. The method according to claim 1, characterized in that The method further comprises: When the second concurrency number reaches the upper limit of the concurrency number, increasing the block size to obtain a second block size; The step of dividing the target file into blocks to obtain a second file block includes: The remaining files in the target file except the first file block are divided into blocks according to the second block size to obtain second file blocks.
8. The method according to any one of claims 1 to 7, characterized in that: The method further comprises: When the received detection result is that the file signature information has been detected, the file path corresponding to the file to be uploaded returned by the server is received, and the block processing of the target file is stopped.
9. A file uploading device, characterized in that: The device comprises: The acquisition module is used to obtain the file to be uploaded and the corresponding file size; A first block processing module, configured to, when the file size exceeds a file size threshold, perform block processing on the file to be uploaded according to a preset block parameter value and upload the file, and simultaneously calculate file signature information of the file to be uploaded; A sending module, used for sending the file signature information to the server; A receiving module, used for receiving the detection result of the file signature information returned by the server; The sending module is further configured to send an interface call request to the server when the received detection result is that the file signature information is not detected; A second block processing module is used to obtain a first file block from a target file, upload the first file block, and determine a time consumption value for uploading the first file block when the response time of the interface call request exceeds a preset time; the target file includes files to be uploaded except the uploaded file blocks, and the uploaded file blocks are file blocks that have been uploaded after the files to be uploaded are processed by block processing; The second block processing module is further configured to reduce the block size to obtain a first block size when the upload time value reaches a first time threshold, perform block processing on the remaining files in the target file except the first file block according to the first block size to obtain a second file block, and upload the second file block; The second block processing module is also used to increase the upload concurrency number when the upload time value is lower than the first time threshold, obtain a second concurrency number, block-process the remaining files in the target file except the first file block, obtain a second file block, and upload the second file block according to the second concurrency number.
10. The device according to claim 9, characterized in that The second block processing module is also used for: Sending an interface call request carrying the file identifier of the file to be uploaded and the file block sequence number of the file block to be uploaded in the file to be uploaded to the server, so that the server stores the file block sequence number of the file block to be uploaded and returns the file block signature information of the file block to be uploaded; The file block sequence number and file block signature information of the file block to be uploaded are cached.
11. The device according to claim 10, characterized in that The device is also used for: After all file blocks of the file to be uploaded are uploaded, the file block sequence number and the corresponding file block signature information of each file block are sent to the server, so that the server verifies the file block sequence number and the corresponding file block signature information. After the verification is successful, the uploaded file blocks are spliced according to the file block sequence number and the corresponding file block signature information to obtain the file to be uploaded, and the file path of the file to be uploaded is returned.
12. The device according to claim 9, characterized in that The second block processing module is also used for: When the first block size reaches a first block size threshold, reducing the number of concurrent uploads to obtain a first concurrent number; The second file block is uploaded according to the first concurrent number.
13. The device according to claim 12, characterized in that The second block processing module is also used for: After uploading the second file block according to the first concurrent number, obtaining a transmission time consumption value of the second file block; When the transmission time value exceeds the first time threshold and the first block size reaches the first block size threshold, continue to reduce the number of concurrent uploads until the number of concurrent uploads reaches the lower limit of the number of concurrent uploads or the transmission time value is lower than the first time threshold, and stop reducing the number of concurrent uploads.
14. The device according to claim 9, characterized in that The second block processing module is also used for: When the upload time value reaches a first time threshold and does not exceed a second time threshold, reducing the block size according to a first block reduction value, wherein the second time threshold is greater than the first time threshold; When the upload time value reaches the second time threshold, the block size is reduced according to a second block reduction value, wherein an absolute value of the second block reduction value is greater than an absolute value of the first block reduction value.
15. The device according to claim 9, characterized in that The second block processing module is also used for: When the second concurrency number reaches the upper limit of the concurrency number, increasing the block size to obtain a second block size; The remaining files in the target file except the first file block are divided into blocks according to the second block size to obtain second file blocks.
16. The device according to any one of claims 9 to 15, characterized in that The second block processing module is also used for: When the received detection result is that the file signature information has been detected, the file path corresponding to the file to be uploaded returned by the server is received, and the block processing of the target file is stopped.
17. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 8 are implemented.
18. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.
