bugfix
This commit is contained in:
parent
041fac0e57
commit
6d1936ff7f
@ -7,6 +7,7 @@ import tempfile
|
|||||||
import aiofiles
|
import aiofiles
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
import base64
|
||||||
|
|
||||||
from appPublic.folderUtils import _mkdir
|
from appPublic.folderUtils import _mkdir
|
||||||
from appPublic.base64_to_file import base64_to_file, getFilenameFromBase64
|
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={}):
|
async def downloadfile(url, headers=None, params=None, data={}):
|
||||||
filename = url.split('/')[-1]
|
filename = url.split('/')[-1]
|
||||||
fs = FileStorage()
|
fs = FileStorage()
|
||||||
fpath = fs._name2path(filename, 'tmp')
|
fpath = fs._name2path(filename, userid='tmp')
|
||||||
try:
|
try:
|
||||||
async with aiofiles.open(fpath,'wb') as f:
|
shc = StreamHttpClient()
|
||||||
shc = StreamHttpClient()
|
async for chunk in shc('GET', url,
|
||||||
async for chunk in shc('GET', url,
|
async with aiofiles.open(fpath,'wb') as f:
|
||||||
headers=headers,
|
headers=headers,
|
||||||
params=params,
|
params=params,
|
||||||
data=data):
|
data=data):
|
||||||
@ -197,3 +198,14 @@ async def downloadfile(url, headers=None, params=None, data={}):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
exception(f'save {url} to {fpath} exception:{e}'
|
exception(f'save {url} to {fpath} exception:{e}'
|
||||||
raise 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
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
# setup.cfg
|
# setup.cfg
|
||||||
[metadata]
|
[metadata]
|
||||||
name = ahserver
|
name = ahserver
|
||||||
version = 1.0.10
|
version = 1.0.11
|
||||||
description = A application server base on aiohttp
|
description = A application server base on aiohttp
|
||||||
author = yu moqing
|
author = yu moqing
|
||||||
author_email = yumoqing@gmail.com
|
author_email = yumoqing@gmail.com
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user