How to send header in flask send_file?

Alireza picture Alireza · Jul 22, 2015 · Viewed 9.4k times · Source

The problem is I am unable to send headers when using send_file, is there any workaround for this?

I want to be able to send headers when sending files to client.

return send_file(mp3_filepath, 'audio/mpeg')

Answer

0x90 picture 0x90 · Jul 22, 2015
from flask import make_response, send_file    

response = make_response(send_file(mp3_filepath))
response.headers['X-Something'] = 'header value goes here'
return response