-
如题,我尝试了很久,都没有办法能正常通过内存将图片上传到lsky 错误情况 imgByteArr = io.BytesIO(bg.tobytes())
imgByteArr.name = './test.png'
#bg.save(imgByteArr,format='PNG')
img = io.BufferedReader(imgByteArr)
url = "http://127.0.0.1:14700/api/v1/upload"
header = {
"Authorization": "Bearer TOKEN",
"Accept": "application/json"
}
params = {'strategy_id':3}
myfiles = {'file': img}
return requests.post(url, headers=header, params=params,
files=myfiles) # 请求api 权限是没有问题的,bg的类型是 imgByteArr.name = './test.png' 如果不设置名字,就会提示不支持的图片格式;
现在设置了名字后,提示服务异常请稍后再试
唯一可行的情况如下:
我的需求虽然我知道可以用PIL的save方法保存到硬盘里面再重新open,但是这样很耗费时间(实测原本直接上传是1s的处理时间,加上保存到磁盘再open打开,就变成了1.8s,几乎于两倍) 而且保存到磁盘还需要进行随机重命名,避免冲突。
需求就是能通过保存到内存中再上传到lsky,求python大佬教一下 ,感激不尽! |
Beta Was this translation helpful? Give feedback.
Answered by
musnows
Feb 8, 2023
Replies: 1 comment
-
不知道为什么,多上传了一个discussion,关闭这个 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
musnows
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
不知道为什么,多上传了一个discussion,关闭这个