Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send header in flask send_file?

Tags:

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') 
like image 414
Alireza Avatar asked Jul 22 '15 05:07

Alireza


People also ask

How do you set headers on a Flask response?

To set response headers in Flask and Python, we set the headers property of the response object. to call make_response to create response object that returns a string response. Finally, we return the resp object in the home route.

How do you send a file in Flask?

Flask – File Uploading Handling file upload in Flask is very easy. It needs an HTML form with its enctype attribute set to 'multipart/form-data', posting the file to a URL. The URL handler fetches file from request. files[] object and saves it to the desired location.

How do I download multiple files from Flask?

In order to offer several files together as a download, you only have the option of compressing them in an archive. In my example, all files that match the specified pattern are listed and compressed in a zip archive. This is written to the memory and sent by the server.


1 Answers

from flask import make_response, send_file      response = make_response(send_file(mp3_filepath)) response.headers['X-Something'] = 'header value goes here' return response 
like image 120
0x90 Avatar answered Sep 18 '22 11:09

0x90