扫码关注官方订阅号
用php实现很简单
$fileres = file_get_contents('d:/a.jpg'); header('Content-type: image/jpeg'); echo $fileres;
关键词搜索无果,求助~
业精于勤,荒于嬉;行成于思,毁于随。
from django.http import HttpResponse f = open('d:/a.jpg', 'rb') response = HttpResponse(f.read(), content_type='image/jpeg')
针对大的文件需要chunk的话可以使用FileReponse:
from django.http import FileResponse response = FileResponse(open('d:/a.jpg', 'rb'), content_type='image/jpeg')
HttpResponse的实例response对象是个类python字典类型的,你可以这样设置他的头属性:response = HttpResponse(...)response['Content-type'] = 'image/jpeg'
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
针对大的文件需要chunk的话可以使用FileReponse:
HttpResponse的实例response对象是个类python字典类型的,你可以这样设置他的头属性:
response = HttpResponse(...)
response['Content-type'] = 'image/jpeg'