This commit is contained in:
yumoqing 2025-09-23 10:16:21 +08:00
parent 041fac0e57
commit 6d1936ff7f
2 changed files with 17 additions and 5 deletions

View File

@ -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,
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

View File

@ -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