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
|
from snek.system.view import BaseView
|
||||||
|
|
||||||
UPLOAD_DIR = pathlib.Path("./drive")
|
|
||||||
|
|
||||||
|
|
||||||
class UploadView(BaseView):
|
class UploadView(BaseView):
|
||||||
|
|
||||||
@ -37,7 +35,11 @@ class UploadView(BaseView):
|
|||||||
reader = await self.request.multipart()
|
reader = await self.request.multipart()
|
||||||
files = []
|
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
|
channel_uid = None
|
||||||
|
|
||||||
@ -68,17 +70,17 @@ class UploadView(BaseView):
|
|||||||
|
|
||||||
name = str(uuid.uuid4()) + pathlib.Path(filename).suffix
|
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)
|
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():
|
while chunk := await field.read_chunk():
|
||||||
await f.write(chunk)
|
await f.write(chunk)
|
||||||
|
|
||||||
drive_item = await self.services.drive_item.create(
|
drive_item = await self.services.drive_item.create(
|
||||||
drive["uid"],
|
drive["uid"],
|
||||||
filename,
|
filename,
|
||||||
str(file_path.absolute()),
|
str(file_path),
|
||||||
file_path.stat().st_size,
|
file_path.stat().st_size,
|
||||||
file_path.suffix,
|
file_path.suffix,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user