Spaces:
Sleeping
Sleeping
feat: update new LocalStorageService
Browse files
src/expon/presentation/infrastructure/services/storage/local_storage_service.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import os
|
2 |
from fastapi import UploadFile
|
3 |
from uuid import uuid4
|
4 |
-
from pathlib import Path
|
5 |
import shutil
|
6 |
|
7 |
class LocalStorageService:
|
@@ -9,14 +8,14 @@ class LocalStorageService:
|
|
9 |
self.base_path = base_path
|
10 |
os.makedirs(self.base_path, exist_ok=True)
|
11 |
|
12 |
-
def save(self, file: UploadFile) -> str:
|
13 |
-
filename = f"{uuid4()}_{file.filename}"
|
14 |
file_path = os.path.join(self.base_path, filename)
|
15 |
|
16 |
with open(file_path, "wb") as buffer:
|
17 |
shutil.copyfileobj(file.file, buffer)
|
18 |
|
19 |
-
return filename
|
20 |
|
21 |
def delete(self, filename: str):
|
22 |
file_path = os.path.join(self.base_path, filename)
|
|
|
1 |
import os
|
2 |
from fastapi import UploadFile
|
3 |
from uuid import uuid4
|
|
|
4 |
import shutil
|
5 |
|
6 |
class LocalStorageService:
|
|
|
8 |
self.base_path = base_path
|
9 |
os.makedirs(self.base_path, exist_ok=True)
|
10 |
|
11 |
+
def save(self, file: UploadFile, custom_filename: str = None) -> str:
|
12 |
+
filename = custom_filename or f"{uuid4()}_{file.filename}"
|
13 |
file_path = os.path.join(self.base_path, filename)
|
14 |
|
15 |
with open(file_path, "wb") as buffer:
|
16 |
shutil.copyfileobj(file.file, buffer)
|
17 |
|
18 |
+
return filename
|
19 |
|
20 |
def delete(self, filename: str):
|
21 |
file_path = os.path.join(self.base_path, filename)
|