Method for avoiding waste of third-party cloud storage space
Technical Field
The invention relates to a computer application technology, in particular to a method for avoiding waste of a third-party cloud storage space.
Background
A large amount of file resources, such as various file resources of pictures, videos, and documents, which may be attached when multimedia messages are sent, are generated during the use of various web applications and app applications. Storing these accessory resources over time requires a large amount of storage space. Many products will purchase specialized third party cloud storage space, and more usage of third party cloud storage space will of course mean more cost.
The operation of wasting the third-party cloud storage space is described by taking the example that the web application sends the notification message containing the file. In order to improve user experience and reduce response time when a user clicks to send a message, the file is generally required to be asynchronously uploaded to a third-party cloud storage space when the user selects the file, and therefore time-consuming file uploading operation is not required to be performed when the user clicks to send the message. If the user deletes the file, modifies the file and cancels the message sending before clicking the message sending, the file which is originally uploaded to the third-party cloud storage space becomes a useless file, and the third-party cloud storage space is wasted. Or the user selects the same file when sending different notification messages, and the repeated uploading to the third-party cloud storage space also causes waste.
Disclosure of Invention
Aiming at the scene, the invention provides a method for avoiding wasting the third-party cloud storage space. According to the invention, while user experience is ensured, useless files and repeated files can be prevented from being uploaded to a third-party cloud storage space, so that the cloud storage cost is reduced.
Taking the example that the web application sends the notification message containing the file as an example for explanation:
the attributes of the file in the notification message stored in the server are as follows: file hash value, file size, file type, file storage mode, file network address, and whether the file has been sent.
Step 1, when a user selects a file, calculating a hash value, size and type of the file by using a web browser, accessing a local server, inquiring whether the local server already stores the file according to the hash value of the file, if so, setting a file storage mode as local server storage, and setting a file network address as a network address corresponding to a local server storage path, wherein the file uploading operation is not needed at this moment. If the file does not exist in the third-party cloud storage space, whether the file exists in the third-party cloud storage space is inquired, if the file exists in the third-party cloud storage space, the file storage mode is set to be the third-party cloud storage space for storage, the network address of the file is set to be the network address corresponding to the third-party cloud storage space, and at the moment, file uploading operation is not needed. If the file does not exist in the local server and the third-party cloud storage space, a temporary directory is created in the local server, a subdirectory A named by a date is created under the temporary directory, the format of the date is YYYYMMDD, and the file is uploaded to the directory A of the local server by utilizing the mature block uploading technology. After uploading successfully, setting the file storage mode as local server storage, setting the file network address as the network address corresponding to the local server storage path, and setting whether the file has been sent with the attribute as 'no'.
And 2, after the file storage mode and the file network address are obtained in the step 1, storing the hash value, the size and the type, the storage mode and the network address of the file into a database. And the user clicks to send the message, after the message is successfully sent, whether the file is sent or not is set as 'yes', and the receiver accesses the file according to the network address of the file. At this time, the storage mode of the file will possibly be local server storage or third-party cloud storage space storage according to different situations in step 1. If the storage mode is the third-party cloud storage space storage, other operations on the file are not needed. If the storage mode is the storage of the local server, a system task of uploading files to the third-party cloud storage space is started, whether the same files exist in the third-party cloud storage space is inquired again according to the hash value of the files in the first step of the task, if yes, the task is terminated, the file storage mode is updated to be the storage of the third-party cloud storage space, and the network address of the files is set to be the network address corresponding to the third-party cloud storage space. And if the file does not exist in the third-party cloud storage space, uploading the file to the third-party cloud storage space, after the file is uploaded successfully, storing the updated file in the third-party cloud storage space, and setting the network address of the file as the network address corresponding to the third-party cloud storage space.
And 3, in the step 1, if the file does not exist in the local server and the third-party cloud storage space, after the file is successfully uploaded to the temporary directory of the local server, if the user selects to delete the multimedia file and modify the multimedia file, directly deleting or modifying the file stored in the local server. If the user cancels the sending of the notification message, the system starts the task of deleting the files in the temporary directory every day because the files stored in the local server are stored in the subdirectory A named by the date in the step 1, and the redundant files are ensured to be deleted.
The task flow of deleting the temporary directory file is as follows:
and acquiring the current system date C and the current system date D, wherein the format is YYYYMMDD, traversing the subdirectories of the temporary directory, and if the temporary directory has the subdirectory named D, traversing the subdirectory to acquire the network addresses corresponding to all files under the subdirectory. And inquiring the database according to the network address of the file, directly deleting the file if no record exists, and judging whether the file can be deleted according to whether the file has sent the attribute if the record exists. If the sent attribute is 'no', the file is directly deleted, and if the sent attribute is 'yes', the file in the message record points to the address, and the file cannot be deleted. The recorded situation may be that the system task of uploading the file to the third-party cloud storage space in step 2 fails to upload, at this time, the file is copied to the subdirectory with the name of C, the network address of the file recorded in the database is updated at the same time, and then the system task of uploading the file to the third-party cloud storage space is started.
The invention has the following beneficial effects:
according to the method, the file is uploaded to the local server firstly, the user confirms the message to be sent and then uploads the file to the third-party cloud storage space, and therefore the waste of the third-party storage space and the flow caused by file deletion and file modification before the message is sent is avoided.
When the files with the same file hash value appear, the uploading operation is not carried out any more, the efficiency is improved, and the waste of third-party storage space and flow caused by the uploading of the repeated files is avoided.
Detailed Description
A method for avoiding wasting a third-party cloud storage space is capable of preventing useless files and repeated files from being uploaded to the third-party cloud storage space while ensuring user experience, and therefore cloud storage cost is reduced.
Taking the example that the web application sends the notification message containing the file as an example for explanation:
the attributes of the file in the notification message stored in the server are as follows: file hash value, file size, file type, file storage mode, file network address, and whether the file has been sent.
Step 1, when a user selects a file, calculating a hash value, size and type of the file by using a web browser, accessing a local server, inquiring whether the local server already stores the file according to the hash value of the file, if so, setting a file storage mode as local server storage, and setting a file network address as a network address corresponding to a local server storage path, wherein the file uploading operation is not needed at this moment. If the file does not exist in the third-party cloud storage space, whether the file exists in the third-party cloud storage space is inquired, if the file exists in the third-party cloud storage space, the file storage mode is set to be the third-party cloud storage space for storage, the network address of the file is set to be the network address corresponding to the third-party cloud storage space, and at the moment, file uploading operation is not needed. If the file does not exist in the local server and the third-party cloud storage space, a temporary directory is created in the local server, a subdirectory A named by a date is created under the temporary directory, the format of the date is YYYYMMDD, and the file is uploaded to the directory A of the local server by utilizing the mature block uploading technology. After uploading successfully, setting the file storage mode as local server storage, setting the file network address as the network address corresponding to the local server storage path, and setting whether the file has been sent with the attribute as 'no'.
And 2, after the file storage mode and the file network address are obtained in the step 1, storing the hash value, the size and the type, the storage mode and the network address of the file into a database. And the user clicks to send the message, after the message is successfully sent, whether the file is sent or not is set as 'yes', and the receiver accesses the file according to the network address of the file. At this time, the storage mode of the file will possibly be local server storage or third-party cloud storage space storage according to different situations in step 1. If the storage mode is the third-party cloud storage space storage, other operations on the file are not needed. If the storage mode is the storage of the local server, a system task of uploading files to the third-party cloud storage space is started, whether the same files exist in the third-party cloud storage space is inquired again according to the hash value of the files in the first step of the task, if yes, the task is terminated, the file storage mode is updated to be the storage of the third-party cloud storage space, and the network address of the files is set to be the network address corresponding to the third-party cloud storage space. And if the file does not exist in the third-party cloud storage space, uploading the file to the third-party cloud storage space, after the file is uploaded successfully, storing the updated file in the third-party cloud storage space, and setting the network address of the file as the network address corresponding to the third-party cloud storage space.
And 3, in the step 1, if the file does not exist in the local server and the third-party cloud storage space, after the file is successfully uploaded to the temporary directory of the local server, if the user selects to delete the multimedia file and modify the multimedia file, directly deleting or modifying the file stored in the local server. If the user cancels the sending of the notification message, the system starts the task of deleting the files in the temporary directory every day because the files stored in the local server are stored in the subdirectory A named by the date in the step 1, and the redundant files are ensured to be deleted.
The task flow of deleting the temporary directory file is as follows:
and acquiring the current system date C and the current system date D, wherein the format is YYYYMMDD, traversing the subdirectories of the temporary directory, and if the temporary directory has the subdirectory named D, traversing the subdirectory to acquire the network addresses corresponding to all files under the subdirectory. And inquiring the database according to the network address of the file, directly deleting the file if no record exists, and judging whether the file can be deleted according to whether the file has sent the attribute if the record exists. If the sent attribute is 'no', the file is directly deleted, and if the sent attribute is 'yes', the file in the message record points to the address, and the file cannot be deleted. The recorded situation may be that the system task of uploading the file to the third-party cloud storage space in step 2 fails to upload, at this time, the file is copied to the subdirectory with the name of C, the network address of the file recorded in the database is updated at the same time, and then the system task of uploading the file to the third-party cloud storage space is started.