Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从服务器发送前更改文件名_Python_Html_Flask_Sendfile_Rawimage - Fatal编程技术网

Python 从服务器发送前更改文件名

Python 从服务器发送前更改文件名,python,html,flask,sendfile,rawimage,Python,Html,Flask,Sendfile,Rawimage,我正在为照片创建存储,但我有一个问题:浏览器无法显示原始图像格式。因此,我需要以某种方式转换它们,最简单和最快的方法是替换文件名中的扩展名(例如:“L2A9696.cr2”=>“L2A9696.jpeg”),而不更改目录本身!我设法对附加文件执行此操作,但我希望它对网页上的文件起作用 我有一个想法:将文件保存到内存中(使用BytesIO),然后更改其扩展名,但我不知道怎么做 raw_list = ["ari", "dpx", "arw"

我正在为照片创建存储,但我有一个问题:浏览器无法显示原始图像格式。因此,我需要以某种方式转换它们,最简单和最快的方法是替换文件名中的扩展名(例如:“L2A9696.cr2”=>“L2A9696.jpeg”),而不更改目录本身!我设法对附加文件执行此操作,但我希望它对网页上的文件起作用

我有一个想法:将文件保存到内存中(使用BytesIO),然后更改其扩展名,但我不知道怎么做

raw_list = ["ari", "dpx", "arw", "srf", "sr2", "bay", "crw", "cr2", "cr3", "dng", "dcr", "kdc", "erf", "3fr", "mef", "mrw", "nef", "nrw", "orf", "ptx", "pef", "raf", "rwl", "dng", "raw", "rw2", "r3d", "srw", "x3f"]
path = get_file_path(file)
        if file.name.split('.')[-1].lower() in raw_list:
            return send_file(f'{data_dir}/{path}{file.name}', mimetype='image/jpeg', as_attachment = True, attachment_filename = ''.join(file.name.split('.')[:-1]) + '.jpeg')