我正在尝试将多个图像压缩到一个压缩文件中
虽然它是一个Django应用程序,但文件并不存储在同一个应用程序中。我想从url列表中获取它们
我得到以下错误:FileNotFoundError [Errno 2] No such file or directory: 'image1.jpg'
def download_image(request):
fotos = ['https://storage.googleapis.com/some/image1.jpg', 'https://storage.googleapis.com/some/image2.jpg']
f = StringIO()
zip = ZipFile(f, 'w')
for foto in fotos:
url = urlopen(foto)
filename = str(foto).split('/')[-1]
zip.write(filename, url.read())
zip.close()
response = HttpResponse(f.getvalue(), content_type="application/zip")
response['Content-Disposition'] = 'attachment; filename=image-test.zip'
return response
我看了几篇文章,最后看了这篇how can I export multiple images using zipfile and urllib2 - django
但我不能让它工作。欢迎提供任何线索。提前谢谢
Perthe ^{} documentation ,} ,它可以传递实际的文件内容
write()
用于将现有文件写入文件系统(通过路径)。我认为您正在寻找^{相关问题 更多 >
编程相关推荐