File import method and device, storage medium and processor
By using WebSocket technology in Web services, the problem of not being able to actively push information under the HTTP protocol is solved, real-time feedback and user experience are improved in the file import process.
Patent Information
- Application Number
- CN202510213271.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-25
- Publication Date
- 2025-05-09
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
During the file import process of traditional web services based on HTTP protocol, the server cannot actively push information to the client, resulting in users being unable to understand the import progress and errors in real time, and the user experience is poor.
WebSocket technology is used to establish a full duplex connection between the client and the server, receive files uploaded by the client through WebSocket connection and perform data import operations, and return the import results in real time.
Real-time interaction between the client and the server is realized, and users can obtain import results in a timely manner, improving the user experience and the interactivity of the application.
Smart Images

Figure CN119967046A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a file importing method, device, storage medium and processor. Background Art
[0002] Web (World Wide Web) services are application components that communicate over the Internet or an intranet using standardized Web protocols (such as HTTP, HTTPS). They allow different applications to run on different platforms and communicate with each other without having to consider the underlying technical details. Web services provide a way to build distributed applications, allowing different systems to easily exchange data and services.
[0003] Traditional web services usually rely on the HTTP protocol for communication between clients and servers. HTTP is a request-response protocol, which means that the client initiates a request, the server processes the request and returns the corresponding response. This interaction mode is effective in most cases, but it has a significant limitation: the server cannot actively push information to the client. This is because HTTP itself is designed as a stateless protocol, and each interaction is initiated by the client.
[0004] In this context, when it comes to functions such as Excel import, the user experience is often negatively affected: due to the limitations of the HTTP protocol, the backend cannot actively notify the frontend about the import progress during the processing of the Excel file, which means that after uploading the Excel file, the user can only passively wait until the entire process is completed, and cannot know the specific processing progress; the user does not know when the import operation is expected to end, nor does he know whether an error or problem occurred during the process. For example, if the import fails or some records are not successfully imported, the user may have to wait until the entire process is completed before seeing the error report. Traditional HTTP-based Web services perform poorly in these aspects, resulting in a serious decline in user experience. Summary of the invention
[0005] Based on the above problems, the present application provides a file import method, device, storage medium and processor, the purpose of which is to improve user experience.
[0006] The embodiments of the present application disclose the following technical solutions:
[0007] The first aspect of the present application provides a file import method, the method comprising:
[0008] Receive the connection request sent by the client and establish a WebSocket connection with the client;
[0009] Based on the WebSocket connection, receiving the file to be imported uploaded by the client;
[0010] Perform a data import operation on the file to be imported, obtain a data import result, and return the data import result to the client.
[0011] Optionally, receiving a connection establishment request sent by a client and establishing a WebSocket connection with the client includes:
[0012] Receive the connection establishment request sent by the client;
[0013] Parsing the connection establishment request to obtain a user identifier or a scene identifier; the user identifier and the scene identifier are set according to a preset rule;
[0014] The user identifier or the scenario identifier is recorded, and a WebSocket connection is established with the client.
[0015] Optionally, performing a data import operation on the file to be imported, obtaining a data import result, and returning the data import result to the client includes:
[0016] Performing a data import operation on the file to be imported to obtain a data import result;
[0017] Based on the user identifier or the scenario identifier, the data import result is returned to the client; the import result includes success, failure or a reason for failure.
[0018] Optionally, performing a data import operation on the file to be imported, obtaining a data import result, and returning the data import result to the client includes:
[0019] Importing data one by one on the contents of the file to be imported, and recording the import result of each piece of data;
[0020] The import result of each piece of data is returned to the client through the WebSocket connection.
[0021] A second aspect of the present application provides a file importing device, the device comprising:
[0022] The connection establishment module is used to receive the connection establishment request sent by the client and establish a WebSocket connection with the client;
[0023] A file receiving module, used for receiving the file to be imported uploaded by the client based on the WebSocket connection;
[0024] The file import module is used to perform a data import operation on the file to be imported, obtain a data import result, and return the data import result to the client.
[0025] Optionally, the connection establishing module is specifically used to:
[0026] Receive the connection establishment request sent by the client;
[0027] Parsing the connection establishment request to obtain a user identifier or a scene identifier; the user identifier and the scene identifier are set according to a preset rule;
[0028] The user identifier or the scenario identifier is recorded, and a WebSocket connection is established with the client.
[0029] Optionally, the file import module is specifically used to:
[0030] Performing a data import operation on the file to be imported to obtain a data import result;
[0031] Based on the user identifier or the scenario identifier, the data import result is returned to the client; the import result includes success, failure or a reason for failure.
[0032] Optionally, the file import module is specifically used to:
[0033] Importing data one by one on the contents of the file to be imported, and recording the import result of each piece of data;
[0034] The import result of each piece of data is returned to the client through the WebSocket connection.
[0035] A third aspect of the present application provides a computer-readable storage medium, in which a computer program is stored. When the program is executed by a processor, a file import method provided in any implementation of the first aspect is implemented.
[0036] A fourth aspect of the present application provides a processor for running a computer program, wherein when the program is run, the file import method provided in any implementation of the first aspect is executed.
[0037] Compared with the prior art, this application has the following beneficial effects:
[0038] The file import method provided by the present application receives a connection establishment request sent by a client, establishes a WebSocket connection with the client, realizes full-duplex communication between the client and the server, and reduces delays compared to the traditional HTTP request-response mode; based on the WebSocket connection, receives the file to be imported uploaded by the client; performs a data import operation on the file to be imported, obtains the data import result, and returns the data import result to the client. By using WebSocket technology, this method provides an effective feedback channel to ensure that users can obtain the import result in a timely manner, which is of great significance for improving the interactivity and user satisfaction of the application, and greatly improves the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0040] Figure 1 A flowchart of a file import method provided in an embodiment of the present application;
[0041] Figure 2 A flowchart of another file import method provided in an embodiment of the present application;
[0042] Figure 3 A schematic diagram of the structure of a file importing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0043] As described above, traditional Web services usually rely on the HTTP protocol for communication between clients and servers. HTTP is a request-response protocol, which means that the client initiates a request, and the server processes the request and returns the corresponding response. This interaction mode is effective in most cases, but it has a significant limitation: the server cannot actively push information to the client. This is because HTTP itself is designed as a stateless protocol, and each interaction is initiated by the client.
[0044] In this context, when it comes to functions such as Excel import, the user experience is often negatively affected: due to the limitations of the HTTP protocol, the backend cannot actively notify the frontend about the import progress during the processing of the Excel file, which means that after uploading the Excel file, the user can only passively wait until the entire process is completed, and cannot know the specific processing progress; the user does not know when the import operation is expected to end, nor does he know whether an error or problem occurred during the process. For example, if the import fails or some records are not successfully imported, the user may have to wait until the entire process is completed before seeing the error report. Traditional HTTP-based Web services perform poorly in these aspects, resulting in a serious decline in user experience.
[0045] In view of the above problems, the inventors have proposed a file import method, device, storage medium and processor after research, which receive a connection establishment request sent by a client and establish a WebSocket connection with the client; based on the WebSocket connection, receive the file to be imported uploaded by the client; perform data import operation on the file to be imported, obtain data import result, and return the data import result to the client.
[0046] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0047] See also Figure 1 , which is a flow chart of a file import method provided by an embodiment of the present application. Figure 1 As shown, the method comprises the following steps:
[0048] S101: Receive a connection request sent by a client and establish a WebSocket connection with the client.
[0049] The process of receiving a connection request sent by a client and establishing a WebSocket connection with the client includes:
[0050] Receive the connection establishment request sent by the client;
[0051] Parsing the connection establishment request to obtain a user identifier or a scene identifier; the user identifier and the scene identifier are set according to a preset rule;
[0052] The user identifier or the scenario identifier is recorded, and a WebSocket connection is established with the client.
[0053] WebSocket is a communication protocol that provides full-duplex communication over a single TCP connection. Through WebSocket, the server and client can achieve more real-time interaction. In order to receive the connection request sent by the client and establish a WebSocket connection with the client, a WebSocket server is set up on the server to listen for the WebSocket connection request from the client. When the server receives the connection request, it receives and establishes the connection.
[0054] In an achievable implementation, a unique user identifier (UID) is defined and used between the client and the server, and specific file import scenario parameters are set and used to distinguish different message types. For example, a unique user ID is generated when a user logs in or registers, and is stored on the client. When a WebSocket connection is established, the user ID is sent to the server as a parameter so that the server can identify the user. When the server receives the WebSocket connection request, it parses the query parameter in the URL to obtain the user ID, associates the user ID with the current connection, and facilitates subsequent push of messages based on the user ID.
[0055] S102: Based on the WebSocket connection, receiving the file to be imported uploaded by the client.
[0056] Leverage the established WebSocket connection to transfer file data, avoiding the frequent connection overhead in traditional HTTP requests.
[0057] S103: Perform a data import operation on the file to be imported, obtain a data import result, and return the data import result to the client.
[0058] The server parses the received file data, performs necessary conversion or verification steps, and then imports the data into the target storage system (such as a database). The server performs the corresponding parsing and data import logic according to the file type, such as data import of CSV and Excel files.
[0059] In an achievable implementation, performing a data import operation on the file to be imported, obtaining a data import result, and returning the data import result to the client includes:
[0060] Performing a data import operation on the file to be imported to obtain a data import result;
[0061] Based on the user identifier or the scenario identifier, the data import result is returned to the client; the import result includes success, failure or a reason for failure.
[0062] To ensure that messages can be pushed correctly to the corresponding users, the server and client need to agree on a unique user identifier (such as a user ID). In this way, even if multiple users import files at the same time, the system can accurately distinguish the activities of each user. For different file import scenarios (such as different types of files or different business logic), specific parameters or tags can be defined to help the client identify and correctly display the corresponding messages.
[0063] In an achievable implementation, performing a data import operation on the file to be imported, obtaining a data import result, and returning the data import result to the client includes:
[0064] Importing data one by one on the contents of the file to be imported, and recording the import result of each piece of data;
[0065] The import result of each piece of data is returned to the client through the WebSocket connection.
[0066] The file import method provided in the embodiment of the present application receives a connection establishment request sent by a client, establishes a WebSocket connection with the client, realizes full-duplex communication between the client and the server, and reduces delays compared to the traditional HTTP request-response mode; based on the WebSocket connection, receives the file to be imported uploaded by the client; performs a data import operation on the file to be imported, obtains a data import result, and returns the data import result to the client. By using WebSocket technology, this method provides an effective feedback channel to ensure that users can obtain the import result in a timely manner, which is of great significance for improving the interactivity and user satisfaction of the application, and greatly improves the user experience.
[0067] See also Figure 2 , which is a flowchart of another file import method provided by an embodiment of the present application. Based on the above embodiment, this embodiment describes in detail a file import method when the file to be imported is an Excel file. Figure 2 As shown, the method comprises the following steps:
[0068] S201: Receive a connection establishment request sent by a client, record the user identifier or the scenario identifier in the connection establishment request, and establish a WebSocket connection with the client.
[0069] Before the user selects an Excel file to import, the client will first try to establish a WebSocket connection with the server. This is usually implemented through JavaScript, such as using new WebSocket(url) to create a new WebSocket instance. Ensure that once the Excel file is processed, messages can be pushed to the client immediately without waiting for the round-trip time of the HTTP request.
[0070] To ensure that messages can be pushed correctly to the corresponding users, the server and client need to agree on a unique user identifier (such as a user ID). In this way, even if multiple users import Excel files at the same time, the system can accurately distinguish the activities of each user. For different Excel import scenarios (such as different types of Excel files or different business logic), specific parameters or tags can be defined to help the client identify and correctly display the corresponding messages.
[0071] For example, all possible scenario types are pre-defined according to business requirements, such as "employee data import" for employee data import, "product inventory update" for product inventory update, etc. Before the client sends any message to the server, it ensures that the message contains the correct scenario parameters. By setting the scenario field in the message, it helps the server understand the purpose of the message and select the appropriate processing logic.
[0072] S202: Based on the WebSocket connection, receive the Excel file uploaded by the client.
[0073] After the user selects the target Excel file on the client, the established WebSocket connection is used to transmit the file data, avoiding the frequent connection overhead in traditional HTTP requests.
[0074] S203: Perform a data import operation on the Excel file to obtain a data import result.
[0075] After receiving the Excel file, the server parses its content and processes the data line by line. For each row of data, after completing the database operation or other processing steps, the server constructs a message containing the import result of the row (success or failure and the reason).
[0076] S204: Based on the user identifier or the scenario identifier, return the data import result to the client.
[0077] Using the established WebSocket connection, the server sends messages to the client, allowing the user to see the processing status of each row of data in real time. After receiving the message returned by the server, the client updates the interface to reflect the latest import status. For example, after processing the row of data, the import result returned by the server to the client should also contain the same scenario identifier, so that the client can display different interface components or processing logic according to different scenarios. This method provides a more transparent user experience, allowing users to clearly understand the status of the entire import process and promptly discover and solve possible problems.
[0078] Another file import method provided by the embodiment of the present application provides a complete solution from the client to the server, ensuring the effectiveness of the real-time processing and feedback mechanism of the Excel file. In this way, the user can understand every detail of the import process in real time, greatly improving the user experience. Moreover, the method realizes the effective management and use of user identification and scene identification, thereby ensuring the accuracy and pertinence of information during the WebSocket communication process, which not only improves the flexibility of the system, but also further enhances the user experience.
[0079] Based on the file importing method introduced in the above embodiment, the present application also provides a file importing device accordingly. Figure 3 Figure 1 is a schematic diagram of the structure of the device. Figure 3 As shown, the file importing device includes:
[0080] The connection establishment module 301 is used to receive a connection establishment request sent by a client and establish a WebSocket connection with the client;
[0081] A file receiving module 302, used for receiving a file to be imported uploaded by a client based on the WebSocket connection;
[0082] The file import module 303 is used to perform a data import operation on the file to be imported, obtain a data import result, and return the data import result to the client.
[0083] Optionally, the connection establishing module is specifically used to:
[0084] Receive the connection establishment request sent by the client;
[0085] Parsing the connection establishment request to obtain a user identifier or a scene identifier; the user identifier and the scene identifier are set according to a preset rule;
[0086] The user identifier or the scenario identifier is recorded, and a WebSocket connection is established with the client.
[0087] Optionally, the file import module is specifically used to:
[0088] Performing a data import operation on the file to be imported to obtain a data import result;
[0089] Based on the user identifier or the scenario identifier, the data import result is returned to the client; the import result includes success, failure or a reason for failure.
[0090] Optionally, the file import module is specifically used to:
[0091] Importing data one by one on the contents of the file to be imported, and recording the import result of each piece of data;
[0092] The import result of each piece of data is returned to the client through the WebSocket connection.
[0093] In addition, an embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. When the program is executed by a processor, a file import method as described in any of the method embodiments is implemented.
[0094] In addition, an embodiment of the present application further provides a processor, which is used to run a computer program, and when the program is run, the file import method described in any implementation manner of the aforementioned method embodiment is executed.
[0095] It should be noted that each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, 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. The device embodiment described above is merely schematic, in which the unit described as a separate component may or may not be physically separated, and the component prompted as a unit may or may not be a physical unit, that is, it may be located in one place, or it may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative work.
[0096] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A file import method, characterized in that: include: Receive the connection request sent by the client and establish a WebSocket connection with the client; Based on the WebSocket connection, receiving the file to be imported uploaded by the client; Perform a data import operation on the file to be imported, obtain a data import result, and return the data import result to the client.
2. The method according to claim 1, characterized in that Receive the connection request sent by the client and establish a WebSocket connection with the client, including: Receive the connection establishment request sent by the client; Parsing the connection establishment request to obtain a user identifier or a scene identifier; the user identifier and the scene identifier are set according to a preset rule; The user identifier or the scenario identifier is recorded, and a WebSocket connection is established with the client.
3. The method according to claim 2, characterized in that Performing a data import operation on the file to be imported, obtaining a data import result, and returning the data import result to the client, including: Performing a data import operation on the file to be imported to obtain a data import result; Based on the user identifier or the scenario identifier, the data import result is returned to the client; the import result includes success, failure or a reason for failure.
4. The method according to claim 1, characterized in that: Performing a data import operation on the file to be imported, obtaining a data import result, and returning the data import result to the client, including: Importing data one by one on the contents of the file to be imported, and recording the import result of each piece of data; The import result of each piece of data is returned to the client through the WebSocket connection.
5. A data import device, characterized in that: include: The connection establishment module is used to receive the connection establishment request sent by the client and establish a WebSocket connection with the client; A file receiving module, used for receiving the file to be imported uploaded by the client based on the WebSocket connection; The file import module is used to perform a data import operation on the file to be imported, obtain a data import result, and return the data import result to the client.
6. The device according to claim 5, characterized in that The connection establishment module is specifically used for: Receive the connection establishment request sent by the client; Parsing the connection establishment request to obtain a user identifier or a scene identifier; the user identifier and the scene identifier are set according to a preset rule; The user identifier or the scenario identifier is recorded, and a WebSocket connection is established with the client.
7. The device according to claim 6, characterized in that The file import module is specifically used for: Performing a data import operation on the file to be imported to obtain a data import result; Based on the user identifier or the scenario identifier, the data import result is returned to the client; the import result includes success, failure or a reason for failure.
8. The device according to claim 5, characterized in that The file import module is specifically used for: Importing data one by one on the contents of the file to be imported, and recording the import result of each piece of data; The import result of each piece of data is returned to the client through the WebSocket connection.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the program is executed by a processor, the file importing method according to any one of claims 1 to 4 is implemented.
10. A processor, characterized in that: Used to run a computer program, which executes the file importing method according to any one of claims 1 to 4 when running.
Citation Information
Cited By
Excel file asynchronous import method, device and system based on EventSource and OSS object storage
CN121985027A