Fixed upload.
This commit is contained in:
parent
c709ee11c9
commit
529ebd23fc
@ -18,8 +18,6 @@ from aiohttp import web
|
||||
|
||||
from snek.system.view import BaseView
|
||||
|
||||
UPLOAD_DIR = pathlib.Path("./drive")
|
||||
|
||||
|
||||
class UploadView(BaseView):
|
||||
|
||||
@ -37,8 +35,12 @@ class UploadView(BaseView):
|
||||
reader = await self.request.multipart()
|
||||
files = []
|
||||
|
||||
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
||||
user_uid = self.request.session.get("uid")
|
||||
|
||||
upload_dir = await self.services.user.get_home_folder(user_uid)
|
||||
upload_dir = upload_dir.joinpath("upload")
|
||||
upload_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
channel_uid = None
|
||||
|
||||
drive = await self.services.drive.get_or_create(
|
||||
@ -68,17 +70,17 @@ class UploadView(BaseView):
|
||||
|
||||
name = str(uuid.uuid4()) + pathlib.Path(filename).suffix
|
||||
|
||||
file_path = pathlib.Path(UPLOAD_DIR).joinpath(name)
|
||||
file_path = upload_dir.joinpath(name)
|
||||
files.append(file_path)
|
||||
|
||||
async with aiofiles.open(str(file_path.absolute()), "wb") as f:
|
||||
async with aiofiles.open(str(file_path), "wb") as f:
|
||||
while chunk := await field.read_chunk():
|
||||
await f.write(chunk)
|
||||
|
||||
drive_item = await self.services.drive_item.create(
|
||||
drive["uid"],
|
||||
filename,
|
||||
str(file_path.absolute()),
|
||||
str(file_path),
|
||||
file_path.stat().st_size,
|
||||
file_path.suffix,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user