访问图像文件 [英] Accessing image files

查看:48
本文介绍了访问图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目中工作,该项目的目录中包含10k张图像,并且希望通过在我的网站中进行搜索来显示这些图像.因此,用户可以通过搜索选择想要的图像,访问该图像并下载.最好的方法是什么?

I'm working in a project which I have a directory with 10k images, and I want display those images, with a search in my website. So, the user can choose the image he wants through the search, access the image, and download it. What is the best way to do that?

推荐答案

图像名称必须与保存在图像目录中的名称相同,之后,当用户单击下载图像时,它将返回图像名称.

name of images must be the same as saved in the image directory, after that when the user clicks to download the image it will return the name of the image.

例如base_path ='E:/images/

e.g. base_path = 'E:/images/

图片名称= request_nme +'.jpg'

image_name = request_nme + '.jpg'

file_path = os.path.join(base_path, image_name)
if os.path.exists(file_path):
    with open(file_path, 'rb') as fh:
        response = HttpResponse(fh, content_type='application/jpg')
        response['Content-Disposition'] = 'attachment; filename=' + os.path.basename(file_path)

这篇关于访问图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆