From 6d1936ff7fe2868f559a4c44417532ac0e4cc688 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 23 Sep 2025 10:16:21 +0800 Subject: [PATCH] bugfix --- ahserver/filestorage.py | 20 ++++++++++++++++---- setup.cfg | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ahserver/filestorage.py b/ahserver/filestorage.py index e8b50d5..518c86a 100644 --- a/ahserver/filestorage.py +++ b/ahserver/filestorage.py @@ -7,6 +7,7 @@ import tempfile import aiofiles import json import time +import base64 from appPublic.folderUtils import _mkdir from appPublic.base64_to_file import base64_to_file, getFilenameFromBase64 @@ -184,11 +185,11 @@ def file_realpath(path): async def downloadfile(url, headers=None, params=None, data={}): filename = url.split('/')[-1] fs = FileStorage() - fpath = fs._name2path(filename, 'tmp') + fpath = fs._name2path(filename, userid='tmp') try: - async with aiofiles.open(fpath,'wb') as f: - shc = StreamHttpClient() - async for chunk in shc('GET', url, + shc = StreamHttpClient() + async for chunk in shc('GET', url, + async with aiofiles.open(fpath,'wb') as f: headers=headers, params=params, data=data): @@ -197,3 +198,14 @@ async def downloadfile(url, headers=None, params=None, data={}): except Exception as e: exception(f'save {url} to {fpath} exception:{e}' raise e + +async def base642file(b64str): + filename = getFilenameFromBase64(b64str) + if ',' in b64str: + header, b64str = b64str.split(',', 1) + fs = FileStorage() + fpath = fs._name2path(filename, userid='tmp') + async with aiofiles.open(fpath, 'wb') as f: + binary_data = base64.b64decode(b64str) + await f.write(binary_data) + return fpath diff --git a/setup.cfg b/setup.cfg index 8572b24..3cbee05 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ # setup.cfg [metadata] name = ahserver -version = 1.0.10 +version = 1.0.11 description = A application server base on aiohttp author = yu moqing author_email = yumoqing@gmail.com