Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
Fig. 1 is a flowchart of a file uploading method according to an embodiment of the present invention, where this embodiment is applicable to a situation where a file in a Node server needs to be uploaded to a storage space conforming to an S3 protocol, and the method may be executed by a file uploading apparatus, as shown in fig. 1, the method of this embodiment specifically includes:
s110, receiving at least one file to be uploaded, and saving the at least one file to be uploaded in a temporary folder of the Node server.
In this embodiment, the user may upload the file resource that is finally uploaded to the storage space following the S3 protocol through the client, and temporarily store the file resource in the Node server corresponding to the client. The Node server is a server written by Node. js, and the Node. js is a server development platform for operating Javascript, so that the Javascript can be developed on the server as PHP, Python and other languages.
Specifically, a user uploads at least one file to be uploaded to a storage space conforming to an S3 protocol at a client, a form of the client sends the at least one file to be uploaded to a Node server, and the Node server stores the received at least one file to be uploaded in a temporary folder for temporary storage after receiving the at least one file to be uploaded.
And S120, calling a Python uploading script module, and uploading the files in the temporary folder through an application programming interface following a simple storage service protocol.
Although the existing Node server cannot directly upload resources to the storage space following the S3 protocol, the Node server can conveniently and quickly call the Python scripting language, and the Python scripting language can also be perfectly adapted to the S3 protocol, so the Python scripting language can be used as an intermediate medium, and the Node server can conveniently and quickly upload the resources therein to the storage space following the S3 protocol, wherein the storage space following the S3 protocol may be a Ceph cluster.
In this embodiment, after saving at least one file to be uploaded in the temporary folder, the Node server may call a preset Python upload script module. The Python upload script module can establish a communication connection with the storage space following the S3 protocol, and can also upload files in the temporary folder to the storage space following the S3 protocol through the API following the S3 protocol.
In the file uploading method provided by this embodiment, at least one file to be uploaded is received, the at least one file to be uploaded is stored in the temporary folder, then the Python uploading script module is called, and the file in the temporary folder is uploaded through the API conforming to the S3 protocol, so that the defect that the existing Node server cannot directly upload the file stored in the Node server to the storage space conforming to the S3 protocol is overcome, and the effect of conveniently and quickly uploading the file in the Node server to the storage space conforming to the S3 protocol is achieved.
On the basis of the foregoing embodiments, further, after receiving at least one file to be uploaded, the method further includes:
and creating an empty temporary folder, wherein the temporary folder is used for storing at least one file to be uploaded.
After receiving at least one file to be uploaded, the Node server needs to store the file to be uploaded in a specific path, and at this time, an empty temporary folder may be preferably created for storing the received at least one file to be uploaded. It should be noted that the temporary folder may be created by the Node server in advance before receiving at least one file to be uploaded, and there is no special requirement for the temporary folder as long as it is empty when the Node server receives at least one file to be uploaded, so as to ensure that only the file that the user needs to upload at this time is stored in the temporary folder.
Example two
Fig. 2 is a flowchart of a file uploading method according to a second embodiment of the present invention. On the basis of the foregoing embodiments, this embodiment may select to receive at least one file to be uploaded, and store the at least one file to be uploaded in a temporary folder of a Node server, including: converting the received at least one file to be uploaded into a file stream; according to a preset rule and the content and format of each file in the file stream, checking the legality of each file in the file stream one by one; and if the file is legal, replacing the original file name of the file by using a random character string, and sequentially storing each file with the original file name replaced in the file stream into the temporary folder. As shown in fig. 2, the method of this embodiment specifically includes:
s210, receiving at least one file to be uploaded, and converting the received at least one file to be uploaded into a file stream.
The Node server converts at least one received file to be uploaded into a file stream so that the Node server can check the validity of each file according to preset rules. The file stream comprises at least one received file to be uploaded, and the file stream has directionality and continuity.
S220, according to the preset rules and the content and format of each file in the file stream, the legality of each file in the file stream is checked one by one.
In this embodiment, a Node server is preset with a file validity check module, which can check the validity of each file in a file stream one by one according to preset rules and the content and format of each file in the file stream. Specifically, the Node server may call the fs tool module to check whether the content of each file in the file stream is empty, and if the content of the file is not empty, determine that the file is a legal file; the Node server can also call a path tool module to check whether the format of each file in the file stream is normalized, and if the format of the file is checked to be normalized, the file is determined to be a legal file; the Node server may further set other preset rules to check the validity of each file in the file stream, where the preset rules may check whether the file in the file stream contains unhealthy content, and if it is checked that the file does not contain unhealthy content, determine that the corresponding file is a legal file.
And S230, if the file is legal, replacing the original file name of the file by using the random character string, and sequentially storing each file with the original file name replaced in the file flow into a temporary folder.
If the files in the file stream are verified to be legal, the original file names of the legal files in the file stream can be replaced by random character strings one by one aiming at the legal files. The original file names of legal files in the file stream are replaced one by using the random character strings, so that the problem of uploading coverage of files with the same name can be effectively prevented, and the problem of messy codes during subsequent Chinese coding can be avoided. The original file names of the legal files in the file stream are replaced by the random character strings one by one, and meanwhile, the legal files with the original file names replaced in the file stream can be sequentially stored in the temporary folder.
If the file in the file stream is checked to be illegal, the illegal file is discarded and is not saved in the temporary folder. Further, regarding the naming of the temporary folder, it is preferable to use the time point when the first legal file is stored. If the temporary folder is created after receiving at least one file to be uploaded, it can also be named by the time point when the temporary folder is created, and if the temporary folder is created in advance, it can also be named by the time point when it is detected that there is a file to be uploaded.
And S240, calling a Python uploading script module, and uploading the files in the temporary folder through an application programming interface following a simple storage service protocol.
The file uploading method provided by this embodiment converts at least one received file to be uploaded into a file stream, checks the legitimacy of each file in the file stream one by one according to the preset rules and the content and format of each file in the file stream, if the file is legal, replaces the original file name of the file with a random character string, sequentially stores each file with the original file name replaced in the file stream into a temporary folder, then calls a Python uploading script module, uploads the files in the temporary folder through an API following the S3 protocol, overcomes the defect that the existing Node server cannot directly upload the files stored therein to a storage space following the S3 protocol, achieves the effect of uploading the files in the Node server to the storage space following the S3 protocol conveniently and quickly, and also effectively prevents the problems of uploading coverage of the files with the same name and code disorder during Chinese coding, in addition, uploading of illegal files is avoided.
On the basis of the foregoing embodiments, after calling a Python upload script module and uploading a file in the temporary folder through an application programming interface conforming to a simple storage service protocol, the method further includes:
and deleting the temporary folder when the uploading of all the files in the temporary folder is detected to be finished.
In this embodiment, when it is detected that all files in the temporary folder are uploaded, it is preferable that the temporary folder be deleted in order to avoid a problem that the Node server is paralyzed due to more and more files in the Node server with the lapse of time. In addition, all files in the temporary folder can be deleted, and only the empty temporary folder is reserved. When the user uploads the file next time, the legal file in the file stream can be directly saved in the temporary folder. At this time, a new temporary folder does not need to be created, and only the name of the existing temporary folder needs to be modified.
EXAMPLE III
Fig. 3 is a flowchart of a file uploading method according to a third embodiment of the present invention. On the basis of the foregoing embodiments, this embodiment may select the Python upload script module to upload the file in the temporary folder through an application programming interface conforming to a simple storage service protocol, where the method includes: calling a first Python script file contained in the Python uploading script module by utilizing the Node file contained in the Python uploading script module; when the first Python script file is connected with a storage space following a simple storage service protocol, reading the file in the temporary folder by using a second Python script file contained in a Python uploading script module, and uploading the file in the temporary folder through an application programming interface following the simple storage service protocol. As shown in fig. 3, the method of this embodiment specifically includes:
s310, receiving at least one file to be uploaded, and saving the at least one file to be uploaded in a temporary folder of the Node server.
S320, calling a first Python script file contained in the Python uploading script module by utilizing the Node file contained in the Python uploading script module.
Preferably, the Python upload script module called by the Node server comprises a Node file and a first Python script file, wherein the Node file can call the first Python script file, and the first Python script file can establish a connection with a storage space following the S3 protocol. That is, the Node file calls the first Python script file to make the Node server establish indirect connection with the storage space following the S3 protocol.
S330, when the first Python script file is connected with a storage space following a simple storage service protocol, reading the file in the temporary folder by using a second Python script file contained in the Python uploading script module, and uploading the file in the temporary folder through an application programming interface following the simple storage service protocol.
Preferably, the Python upload script module further includes a second Python script file, and the script file can read a file in the temporary folder. When the first Python script file is successfully connected with the storage space following the S3 protocol, the second Python script file reads each file in the temporary folder of the Node server to prepare for uploading. After each file in the temporary folder is acquired, the second Python script file establishes connection with an API following the S3 protocol through the interface address parameter in the second Python script file, and uploads the files in the temporary folder through the API. It should be noted here that the interface address parameters in the second Python script file are different for different storage spaces conforming to the S3 protocol.
In addition, as the Python language belongs to the scripting language, the uploaded second Python script file can be directly embedded into the code of the Node server, so that the second Python script file can be conveniently and efficiently called and modified, and the problems of version and compatibility caused by introducing a third-party library do not exist.
In the file uploading method provided by this embodiment, at least one file to be uploaded is received, and the at least one file to be uploaded is stored in a temporary folder of the Node server, then the Node file included in the Python uploading script module is used to call the first Python script file included in the Python uploading script module, the first Python script file included in the Python uploading script module is used to read the file in the temporary folder, and the file in the temporary folder is uploaded through an application programming interface following a simple storage service protocol, so that a defect that the existing Node server cannot directly upload the file stored in the Node server to a storage space following an S3 protocol is overcome, and an effect of conveniently and quickly uploading the file in the Node server to the storage space following the S3 protocol is achieved.
On the basis of the foregoing embodiments, further, after reading the file in the temporary folder by using the second Python script file included in the Python upload script module and uploading the file in the temporary folder through an application programming interface conforming to a simple storage service protocol, the method further includes:
and receiving feedback information returned by the second Python script file, wherein the feedback information is used for determining whether the file in the temporary folder is successfully uploaded.
In this embodiment, when the second Python script file uploads the files in the obtained temporary folder one by one through the API conforming to the S3 protocol, the storage space conforming to the S3 protocol sends feedback information to the second Python script file regardless of whether the file is successfully uploaded. The feedback information is used for determining whether the files in the temporary folder are successfully uploaded. After receiving the feedback information, the second Python script file feeds the feedback information back to the Node server to inform the Node server whether the file is uploaded successfully. And after the Node server obtains the feedback information, the Node server also sends the feedback information to the client so as to inform the user whether the file is uploaded successfully.
If the file uploading fails, the file uploading method in the above embodiments may be used to re-upload the file.
Example four
The embodiment of the invention provides a preferable example of a file uploading method. Wherein, the storage space following the S3 protocol is a Ceph cluster.
S410, receiving at least one file to be uploaded.
S420, creating an empty temporary folder, wherein the temporary folder is used for storing at least one file to be uploaded.
S430, converting the received at least one file to be uploaded into a file stream.
S440, according to the content and the format of each file in the file stream, the legality of each file in the file stream is checked one by one.
S450, if the file is legal, replacing the original file name of the file by using the random character string, and sequentially storing each file with the original file name replaced in the file flow into a temporary folder.
And S460, calling a first Python script file contained in the Python uploading script module by utilizing the Node file contained in the Python uploading script module.
S470, when the first Python script file is connected with the storage space following the simple storage service protocol, reading the file in the temporary folder by using the second Python script file contained in the Python uploading script module, and uploading the file in the temporary folder to the Ceph cluster through the application programming interface following the simple storage service protocol.
And S480, receiving feedback information returned by the second Python script file, wherein the feedback information is used for determining whether the file in the temporary folder is successfully uploaded to the Ceph cluster.
And S490, deleting the temporary folder when the uploading of all the files in the temporary folder is detected to be finished.
In this embodiment, the user uploads at least one file to be uploaded into the storage space conforming to the S3 protocol through the client, and the Node server receives the at least one file to be uploaded. After receiving at least one file to be uploaded, the Node server creates an empty temporary folder for storing the at least one file to be uploaded. Before saving at least one file to be uploaded to the temporary folder, the validity of each file needs to be checked.
Specifically, the Node server converts at least one received file to be uploaded into a file stream, calls a preset file validity checking module to call an fs tool module and a path tool module, and determines whether each file in the file stream is valid or not by respectively checking whether the content of each file in the file stream is empty and whether the format of each file is standardized or not. And if the file in the file stream is verified to be legal, replacing the original file name of each legal file in the file stream by utilizing the random character string one by one aiming at each legal file, and sequentially storing each legal file with the original file name replaced in the file stream into the temporary folder.
After storing each legal file in the file stream into the temporary folder, the Node server calls a preset Python uploading script module, wherein the Python uploading script module comprises a Node file, a first Python script file and a second Python script file. The Node file calls the first Python script file to make the Node server establish indirect connection with the Ceph cluster following the S3 protocol. Thereafter, the second Python script file reads the files in the temporary folder and uploads the files in the temporary folder to the Ceph cluster through the API following the S3 protocol.
When the second Python script file uploads the read files to the Ceph cluster one by one, the Ceph cluster sends feedback information for determining whether the files in the temporary folder are uploaded successfully to the second Python script file, and after the feedback information is received, the second Python script file feeds the feedback information back to the Node server to inform the Node server whether the files are uploaded successfully. And after the Node server obtains the feedback information, the Node server also sends the feedback information to the client so as to inform the user whether the file is uploaded successfully. And deleting the temporary folder when the uploading of all the files in the temporary folder is detected to be finished.
EXAMPLE five
Fig. 5 is a schematic structural diagram of a file uploading apparatus in the fifth embodiment of the present invention. As shown in fig. 5, the file uploading apparatus includes:
a file saving module 510, configured to receive at least one file to be uploaded, and save the at least one file to be uploaded in a temporary folder of the Node server;
and the file uploading module 520 is used for calling the Python uploading script module and uploading the files in the temporary folder through an application programming interface following the simple storage service protocol.
The file uploading device provided by this embodiment receives at least one file to be uploaded by using the file saving module, saves the at least one file to be uploaded in the temporary folder, calls the Python uploading script module by using the file uploading module, and uploads the file in the temporary folder through the API conforming to the S3 protocol, thereby overcoming the defect that the existing Node server cannot directly upload the file stored therein to the storage space conforming to the S3 protocol, and achieving the effect of conveniently and quickly uploading the file in the Node server to the storage space conforming to the S3 protocol.
Further, the apparatus may further include: the temporary folder creating module is used for creating an empty temporary folder after receiving at least one file to be uploaded, and the temporary folder is used for storing the at least one file to be uploaded.
Further, the file saving module 510 may specifically include:
the file stream conversion submodule is used for converting the received at least one file to be uploaded into a file stream;
the file legality checking submodule is used for checking the legality of each file in the file stream one by one according to a preset rule and the content and format of each file in the file stream;
and the file saving submodule is used for replacing the original file name of the file by using the random character string if the file is legal, and sequentially saving each file with the original file name replaced in the file stream into the temporary folder.
Further, the file uploading module 520 may specifically include:
the first Python script file calling submodule is used for calling a first Python script file contained in a Python uploading script module by utilizing a Node file contained in the Python uploading script module;
and the file reading and uploading sub-module is used for reading the files in the temporary folder by using a second Python script file contained in the Python uploading script module when the first Python script file is connected with the storage space following the simple storage service protocol, and uploading the files in the temporary folder through an application programming interface following the simple storage service protocol.
Further, the apparatus may further include:
and the temporary folder deleting module is used for deleting the temporary folder when detecting that all files in the temporary folder are completely uploaded after calling the Python uploading script module and uploading the files in the temporary folder through an application programming interface following a simple storage service protocol.
Further, the apparatus may further include:
and the feedback information receiving module is used for reading the file in the temporary folder by using the second Python script file contained in the Python uploading script module, and receiving feedback information returned by the second Python script file after uploading the file in the temporary folder through an application programming interface following a simple storage service protocol, wherein the feedback information is used for determining whether the file in the temporary folder is successfully uploaded.
The file uploading device provided by the embodiment of the invention can execute the file uploading method provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
EXAMPLE six
Fig. 6 is a schematic structural diagram of a Node server according to a sixth embodiment of the present invention. FIG. 6 illustrates a block diagram of an exemplary Node server 612 suitable for use in implementing embodiments of the present invention. The Node server 612 shown in fig. 6 is only an example, and should not bring any limitation to the function and the scope of the application of the embodiments of the present invention.
As shown in FIG. 6, Node server 612 is in the form of a general purpose computing device. The components of Node server 612 may include, but are not limited to: one or more processors 616, a memory 628, and a bus 618 that connects the various system components (including the memory 628 and the processors 616).
Bus 618 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, and a processor or local bus using any of a variety of bus architectures. By way of example, such architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, micro-channel architecture (MAC) bus, enhanced ISA bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
The Node server 612 typically includes a variety of computer system readable media. These media may be any available media that can be accessed by the Node server 612 and includes both volatile and nonvolatile media, removable and non-removable media.
The memory 628 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM)630 and/or cache memory 632. The Node server 612 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage 634 may be used to read from and write to non-removable, nonvolatile magnetic media (not shown in FIG. 6, and commonly referred to as a "hard drive"). Although not shown in FIG. 6, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In such cases, each drive may be connected to bus 618 by one or more data media interfaces. Memory 628 may include at least one program product having a set (e.g., at least one) of program modules that are configured to carry out the functions of embodiments of the invention.
A program/utility 640 having a set (at least one) of program modules 642 may be stored, for example, in memory 628, such program modules 642 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which examples or some combination thereof may comprise an implementation of a network environment. The program modules 642 generally perform the functions and/or methods of the described embodiments of the present invention.
The Node server 612 may also communicate with one or more external devices 614 (e.g., keyboard, pointing device, display 624, etc., where the display 624 may or may not be configured as desired), one or more devices that enable a user to interact with the Node server 612, and/or any device (e.g., network card, modem, etc.) that enables the Node server 612 to communicate with one or more other computing devices. Such communication may occur via input/output (I/O) interfaces 622. Also, the Node server 612 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN) and/or a public network, such as the Internet) via the network adapter 620. As shown, the network adapter 620 communicates with the other modules of the Node server 612 via bus 618. It should be appreciated that although not shown in FIG. 6, other hardware and/or software modules may be used in conjunction with the Node server 612, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage, among others.
The processor 616 executes various functional applications and data processing, such as implementing a file upload method provided by an embodiment of the present invention, by executing programs stored in the memory 628.
EXAMPLE seven
The seventh embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements a file uploading method provided in the embodiments of the present invention, and the method includes:
receiving at least one file to be uploaded, and storing the at least one file to be uploaded in a temporary folder of the Node server;
and calling a Python uploading script module, and uploading the files in the temporary folder through an application programming interface following a simple storage service protocol.
Of course, the computer program stored on the computer-readable storage medium provided in the embodiments of the present invention is not limited to execute the method operations described above, and may also execute related operations in the Node server-based file uploading method provided in any embodiment of the present invention.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.