gpt4 book ai didi

python - 如何将图像保存到磁盘

转载 作者:太空宇宙 更新时间:2023-11-04 08:13:58 24 4
gpt4 key购买 nike

I working on a mobile application, where user can upload images, am using Django in server side.

我有两种方式获取图片,我想在异常(exception)情况下将图片保存到磁盘。

imageFile = request.FILES['image']
try:
file_path = imageFile.temporary_file_path()
except AttributeError as e:
logger.debug(virtualFile')
imageStringBuffer = imageFile.read()
virtualFile = StringIO.StringIO(imageStringBuffer)
# want to save the imageStringBuffer to disk

I want to to save the 'virtualFile' (in except case) to the disk , How can I do it?

最佳答案

def handle_uploaded_file(f):
with open('imgepath', 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)

引用:here

关于python - 如何将图像保存到磁盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17693231/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com