Sfoglia il codice sorgente

✨ feat(files): add file upload functionality

- add createObject method to MinioService for file uploads
- support specifying content type with default value
- automatically ensure bucket exists before uploading
- return file URL after successful upload
- add error handling and logging for upload operations
yourname 8 mesi fa
parent
commit
58a72d1fd8
1 ha cambiato i file con 15 aggiunte e 0 eliminazioni
  1. 15 0
      src/server/modules/files/minio.service.ts

+ 15 - 0
src/server/modules/files/minio.service.ts

@@ -158,6 +158,21 @@ export class MinioService {
     }
   }
 
+  // 上传文件
+  async createObject(bucketName: string, objectName: string, fileContent: Buffer, contentType: string = 'application/octet-stream') {
+    try {
+      await this.ensureBucketExists(bucketName);
+      await this.client.putObject(bucketName, objectName, fileContent, fileContent.length, {
+        'Content-Type': contentType
+      });
+      logger.db(`Created object: ${bucketName}/${objectName}`);
+      return this.getFileUrl(bucketName, objectName);
+    } catch (error) {
+      logger.error(`Failed to create object ${bucketName}/${objectName}:`, error);
+      throw error;
+    }
+  }
+
   // 删除文件
   async deleteObject(bucketName: string, objectName: string) {
     try {