A method and system for creating real files of a specified size and type

By using pre-set template files and adding noise, real files of a specified size and type are automatically created, solving the problem of low efficiency in test file creation in existing technologies and achieving efficient and accurate file creation and testing.

CN115391285BActive Publication Date: 2026-03-10FUJIAN TIANQUAN EDUCATION TECH LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-05-19
Publication Date
2026-03-10

AI Technical Summary

Technical Problem

Existing technologies are inefficient in creating test files, cannot be reused, and cannot meet the needs of different types and sizes of files, resulting in testing limitations and additional time consumption.

Method used

By using pre-set template files, it creates real files of specified size and type based on file type and size, adds random noise, and performs uploading, transcoding, and content detection, while automatically cleaning up used files.

Benefits of technology

It improves the efficiency and accuracy of test files, can automatically create playable and viewable real files, meets the needs of multiple tests, reduces manual preparation time, and ensures the reliability of test results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115391285B_ABST
    Figure CN115391285B_ABST
Patent Text Reader

Abstract

This invention provides a method for creating real files of a specified size and type. The method includes the following steps: Step S1, pre-setting template files of different sizes; Step S2, creating a new file, passing in the creation type and size of the new file; Step S3, determining whether the new file is within the legal range based on the passed-in new file type value; Step S4, selecting the corresponding template file based on the passed-in new file size value; Step S5, using the obtained template file, adding a specific number of noise points to the template file; Step S6, using the new file created in the previous step for uploading, transcoding, and content detection operations; Step S7, after successful upload, clearing the created local file. This invention can create files of a specified size and type.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer software system technology, and in particular to a method and system for creating real files of a specified size and type. Background Technology

[0002] In daily testing of content services and file processing services, it is often necessary to create test files of different types, sizes, and contents. Previously, test data was created manually first, requiring extra time for each regression test. Later, a script was used to create temporary random files, but these files could not be played or viewed, nor could they be used in file processing scenarios, thus exhibiting certain limitations.

[0003] Due to usage scenario limitations, a file can only be used once and cannot be reused (the second upload of the same file follows a different logic than the initial upload). Therefore, when testing this scenario, files with different content need to be prepared. For ease of testing, automatically created RAR files are used for automated testing, supplemented by manually created files for verification. However, the manual test file creation approach requires creating new files for each version iteration's functional regression testing, and these files need to be unused, have a specific size range, and a specific format, requiring additional time and having certain limitations. Summary of the Invention

[0004] To overcome the above problems, the purpose of this invention is to provide a method for creating real files of a specified size and type.

[0005] This invention is implemented using the following scheme: a method for creating real files of a specified size and type, the method comprising the following steps: Step S1, presetting template files of different sizes;

[0006] Step S2: Create a new file, passing in the file type and size;

[0007] Step S3: Determine whether the new file is within the legal range based on the input new file type value;

[0008] Step S4: Select the corresponding template file based on the new file size value.

[0009] Step S5: Using the obtained template file, add a set number of noise points to the template file;

[0010] Step S6: Use the new file created in the previous step to perform upload, transcoding, and content detection operations;

[0011] Step S7: After successful upload, clear the created local files.

[0012] Furthermore, step S1 is further specified as follows: prepare image files of different sizes, set template files, the template files include template file A and template file B, template file A is an image file between 1M and 10M in size, and template file B is an image file larger than 10M in size.

[0013] Furthermore, step S2 specifically involves creating new files that support the following file types: jpg, jpeg, png, bmp, and webp.

[0014] Furthermore, step S3 is further specified as follows: determine whether the newly created file type is within the supported range; if yes, proceed to the next step; otherwise, exit the file creation process.

[0015] Furthermore, step S5 is further specified as follows: by using the selected template file, editing the template file, and adding random noise based on the difference between the size value of the template file and the size value of the file to be created, with the amount of random noise added depending on the difference.

[0016] Furthermore, step S7 is further specified as follows: once a created file has been used, it will be added to the recycling queue and automatically cleaned up and recycled by the system.

[0017] This invention also provides a system for creating real files of a specified size and type, including a preset module, a creation module, an input module, a selection module, a usage module, an operation module, and a clearing module; the preset module presets template files of different sizes; the creation module creates new files by inputting the creation type and size of the new file; the input module determines whether the new file is within a legal range based on the input new file type value; the selection module selects the corresponding template file based on the input new file size value; the usage module uses the obtained template file and adds a set number of noise points to the template file; the operation module uses the new file created in the previous step to perform upload, transcoding, and content detection operations; and the clearing module clears the created local file after successful upload.

[0018] Furthermore, the preset module is further specifically defined as follows: preparing image files of different sizes, setting template files, the template files including template file A and template file B, template file A being an image file between 1M and 10M in size, and template file B being an image file larger than 10M in size.

[0019] Furthermore, the creation module specifically supports creating new files in the following formats: jpg, jpeg, png, bmp, and webp.

[0020] Furthermore, the input module specifically determines whether the newly created file type is within the supported range; if yes, proceed to the next step; otherwise, exit the file creation process.

[0021] Furthermore, the module is further specified as follows: by using a selected template file, editing the template file, and adding random noise based on the difference between the size of the template file and the size of the file to be created, with the amount of random noise added depending on the difference.

[0022] Furthermore, the cleaning module specifically means that once a created file has been used, it will be added to the recycling queue and automatically cleaned up and recycled by the system.

[0023] The beneficial effects of this invention are as follows: This invention can automatically create realistic images, documents, and other types of files for testing. By using preset template files and editing the file metadata on the basis of the template files, new playable and viewable files can be obtained. There is no need to spend extra time preparing and collecting test data, which improves work efficiency. Moreover, by using real files for testing, it can also directly view and verify the uploaded file content in scenarios that require secondary verification (such as file transcoding, content detection, etc.), and will not result in the file actually failing during secondary processing, thus improving the accuracy of test results. Attached Figure Description

[0024] Figure 1 This is a schematic diagram of the method flow of the present invention.

[0025] Figure 2 This is a system principle block diagram of the present invention. Detailed Implementation

[0026] The invention will now be further described with reference to the accompanying drawings.

[0027] Please see Figure 1 As shown, the present invention provides a method for creating real files of a specified size and type, the method comprising the following steps: Step S1, presetting template files of different sizes;

[0028] Step S2: Create a new file, passing in the file type and size;

[0029] Step S3: Determine whether the new file is within the legal range based on the input new file type value;

[0030] Step S4: Select the corresponding template file based on the new file size value.

[0031] Step S5: Using the obtained template file, add a specific number of noise points to the template file;

[0032] Step S6: Use the new file created in the previous step to perform upload, transcoding, and content detection operations;

[0033] Step S7: After successful upload, clear the created local files.

[0034] The present invention will be further illustrated by a specific embodiment below:

[0035] Step 101: Prepare template files. You can prepare some image files of different sizes in advance (the template files can be prepared according to the frequency of use of the created files. For example, if the frequency of creating small files is very high, then the prepared template files can be 100KB in size, etc.) for easy illustration. In the example, template file A is set to a 1M image file and template file B is a 10M image file.

[0036] Step 102: Pass in the file type (ext) value (supported types include: jpg, jpeg, png, bmp, webp, etc.) and the file size (size) value. These two basic pieces of information are used to create the file.

[0037] Step 103: Based on step 102, determine whether the input ext value is within the supported range, and whether the input size value is a valid value. If the input size value is invalid, such as a size value less than or equal to 0, or a non-int type, the file creation process will exit directly. If the size value is valid, continue with the creation process in step 104.

[0038] Step 104: Select the corresponding template file based on the size value passed in Step 102. For example, if the passed size is 2M, then select template file A as described in Step 101.

[0039] Step 105: Using the template file A selected in Step 104, given that template file A has a size of 1MB and the desired file size is 2MB (a difference of 1MB), edit template file A by adding 1MB of random noise (even if template file A is used to create 2MB files each time, the random noise will result in different noise points, leading to different MD5 values ​​and ensuring the files are unused). Save the edited file as the ext type specified in Step 102. This creates a new 2MB image file locally.

[0040] Step 201: Use the new file created in step 105 to perform operations such as uploading, content inspection, and transcoding.

[0041] 1. Taking the upload scenario as an example for explanation:

[0042] Resource uploading is a common core function of the content service (the system under test mentioned in the background above), supporting the uploading of local files to the server. To improve upload efficiency, the content service supports an instant upload function (i.e., it checks if the file already exists on the server; if it does, it directly returns the file information; otherwise, it switches to the normal upload process). Therefore, when testing upload scenarios, it's necessary to prepare a new, unused file for uploading to avoid triggering the instant upload process and affecting the judgment of test results.

[0043] 2. Taking content detection as an example for explanation:

[0044] The content detection function, simply put, is the detection of pornography, violence, and political content in resources. It supports the detection of pornography, violence, and political content in image resources. First, an image file is created using this system and uploaded to the system under test (the content service mentioned in the background above). The system under test submits the uploaded file to a third-party content detection service for detection and processes and returns the detection results. Then, testing and verification are performed based on the returned results. (The uploaded resource has no requirements regarding file content, but the content detection scenario requires a real file stream. Therefore, creating a test file through this system effectively avoids content detection failures caused by test resource issues, thereby improving the accuracy and reliability of the test results.)

[0045] Step 202: After step 201, clear the locally created test files. Once a file is used (simply called by an upload method), it will be added to the recycling queue and automatically cleaned up by the system. Additionally, a scheduled task (automatically cleaning up files older than 7 days) is running to clean up the local storage paths of created files. This ensures timely release of local disk space, eliminating concerns about insufficient disk space due to locally created files.

[0046] For example, to create a 5MB JPG file (currently supported image types include jpg / jpeg / png / bmp / webp, etc.), the program selects the corresponding JPG template and adds a specific number of pixel noise points (calculated by the size of the selected template file and the desired file size) to the template file. The number of noise points is the same, but their placement is different each time, ensuring the generated file is unique – the uniqueness can be verified using the MD5 hash. This results in a JPG file of a specific size that can be opened and viewed normally, and allows for further processing and testing. It can meet the needs of all file usage scenarios, including content services and file processing.

[0047] For example, when creating a 1MB text file (currently supported document types include txt / docx / pptx, etc.) in docx format, the program selects the corresponding docx template and appends a specified amount of random content (calculated by the size of the selected template file and the expected file size) to the template content. This results in a docx file of the specified size that can be opened and viewed normally, and allows for further processing and testing of the processed file.

[0048] It can be used to create audio files, video files, etc.

[0049] In summary, this invention can automatically create real files of a specified size and type: by using a preset template file, the file metadata is edited based on the template file to obtain a new playable and viewable file.

[0050] Please see Figure 2 As shown, the present invention also provides a system for creating real files of a specified size and type, including a preset module, a creation module, an input module, a selection module, a usage module, an operation module, and a clearing module; the preset module presets template files of different sizes; the creation module creates new files by inputting the creation type and size of the new file; the input module determines whether the new file is within the legal range based on the input new file type value; the selection module selects the corresponding template file based on the input new file size value; the usage module adds a specific number of noise points to the obtained template file; the operation module performs upload, transcoding, and content detection operations on the new file created in the previous step; and the clearing module clears the created local file after successful upload.

[0051] The preset module is further specified as follows: preparing image files of different sizes, setting template files, the template files include template file A and template file B, template file A is an image file between 1M and 10M in size, and template file B is an image file larger than 10M in size.

[0052] The creation module further specifies that it supports creating new files in the following formats: jpg, jpeg, png, bmp, and webp.

[0053] The input module further specifies that it determines whether the type of the newly created file is within the supported range. If yes, it proceeds to the next step; otherwise, it exits the file creation process.

[0054] The module is further specified as follows: by using a selected template file, editing the template file, and adding random noise based on the difference between the size of the template file and the size of the file to be created, with the amount of random noise added depending on the difference.

[0055] The cleaning module is further defined as follows: once a created file has been used, it will be added to the recycling queue and automatically cleaned up and recycled by the system.

[0056] The above description is only a preferred embodiment of the present invention. All equivalent changes and modifications made within the scope of the claims of the present invention should be included in the scope of the present invention.

Claims

1. A method of creating a real file of a specified size and type, characterized by, The method comprises the following steps: step S1, presetting template files of different sizes; Step S2, creating a new file, and inputting the creation type and size of the new file; Step S3, judging whether the new file is within a legal range according to the input new file type value; Step S4, selecting a corresponding template file according to the input new file size value; Step S5, adding a set number of noise points in the template file by using the obtained template file; Step S6, performing uploading, transcoding and content detection operations by using the new file created in the previous step; Step S7, clearing the created local file after successful uploading. The step S1 is further specifically: preparing picture files of different sizes, and setting template files, wherein the template files include a template file A and a template file B, the template file A is a picture file with a size between 1M and 10M, and the template file B is a picture file with a size greater than 10M. The step S2 is further specifically: the types supported by the created new file are jpg, jpeg, png, bmp and webp; and the step S5 is further specifically: adding random noise points according to the difference between the size value of the template file and the size value of the expected created file, and the more the difference, the more random noise points are added.

2. The method of claim 1, wherein: The step S3 is further specifically: judging whether the type of the created new file is within the supported range, if yes, proceeding to the next step; or if no, exiting the file creation process.

3. The method of claim 1, wherein: The step S7 is further specifically: when the created file is used, the file is added to a recycling queue and automatically cleaned up by the system.

4. A system for creating a real file of a specified size and type, characterized by: The method comprises a presetting module, a creating module, an inputting module, a selecting module, a using module, an operating module and a clearing module; the presetting module is used for presetting template files of different sizes; the creating module is used for creating a new file and inputting the creation type and size of the new file; the inputting module is used for judging whether the new file is within a legal range according to the input new file type value; the selecting module is used for selecting a corresponding template file according to the input new file size value; the using module is used for adding a set number of noise points in the template file by using the obtained template file; the operating module is used for performing uploading, transcoding and content detection operations by using the new file created in the previous step; and the clearing module is used for clearing the created local file after successful uploading. The presetting module is further specifically: preparing picture files of different sizes, and setting template files, wherein the template files include a template file A and a template file B, the template file A is a picture file with a size between 1M and 10M, and the template file B is a picture file with a size greater than 10M. The creating module is further specifically: the types supported by the created new file are jpg, jpeg, png, bmp and webp; and the using module is further specifically: adding random noise points according to the difference between the size value of the template file and the size value of the expected created file, and the more the difference, the more random noise points are added.

5. A system for creating real files of specified size and type as claimed in claim 4, wherein: The incoming module is further specific: judging whether the created new file type is in the supported range, yes, then entering the next step; no, then exiting the file creation process.

6. The system for creating a real file of a specified size and type of claim 4, wherein: The cleaning module is further specific: when the created file is used, it will be added to the recycling queue, and the system will automatically clean up the recycling.

Citation Information

Patent Citations

  • Accelerating Automated Testing

    US20160342501A1