Google Cloud Storage integration for document persistence¶
Google Cloud Storage (GCS) is integrated into the system as the persistence layer for generated documents, such as reports. This service handles the storage and retrieval of file bytes, allowing the application to offload file management from local storage or the database^[001-todo-code-copy.md].
File Management Service¶
The core integration is managed through the FileManageService interface, implemented by GcsFileManageServiceImpl^[001-todo-code-copy.md]. This service provides a wrapper around the Google Cloud Storage client library (storage) to perform standard blob operations^[001-todo-code-copy.md].
Key capabilities include:
* Blob Creation: Files can be uploaded as MultipartFile objects or raw byte[] arrays to a specified path^[001-todo-code-copy.md].
* Blob Retrieval: Files are retrieved using storage.readAllBytes(blobId)^[001-todo-code-copy.md].
* Directory Listing: The system can list all files within a specific directory prefix using storage.list()^[001-todo-code-copy.md].
* Bulk Deletion: Directories and their contents can be deleted by iterating through blobs and deleting them in batch^[001-todo-code-copy.md].
Pathing and Naming Conventions¶
Storage paths are constructed dynamically based on the document type and context^[001-todo-code-copy.md].
- Report Documents: For reports (e.g., CSV, PDF), the path is generated using a prefix configured via
GcpUtil.getPrefixFolder()combined with the specific path defined in theReportDocumentTypeenum^[001-todo-code-copy.md]. - User Content: For uploads like images or videos, the path uses a hashed structure.
- The filename is generated using the first 16 characters of the content's MD5 hash^[001-todo-code-copy.md].
- The folder path is generated using the MD5 hash of the bucket name combined with the platform code (
pltCode), taking the first 10 characters^[001-todo-code-copy.md].
Data Flow¶
In the context of report generation, the workflow typically involves:
1. Generation: A service (e.g., CSVDocumentServiceImpl) constructs the file content in memory^[001-todo-code-copy.md].
2. Persistence: The FileManageService writes the bytes to GCS using createBlob()^[001-todo-code-copy.md].
3. Reference: The resulting file path (String) is stored in the database (e.g., in the report_download_record table) to reference the physical file location^[001-todo-code-copy.md].
Related¶
- [[Document generation workflow]]
- [[Google Cloud Platform]]
- [[Report management system]]
Sources¶
^[001-todo-code-copy.md]