Answer the question
In order to leave comments, you need to log in
How to fix error when using send_file in Flask?
Goodnight! I'm trying to transfer a file to a user not from my server, acting as an "intermediary"
# Download from provided URL.
@app.route('/<path:url>')
def download(url):
req = requests.get(url, stream=True)
return send_file(stream_with_context(req.iter_content(1024)), mimetype='mp3')
AttributeError: 'generator' object has no attribute 'read'. How can it be corrected?
Answer the question
In order to leave comments, you need to log in
You can try like this
response = Response(stream_with_context(req.iter_content()), mimetype='audio/mpeg')
response.headers['Content-Disposition'] = 'attachment; filename=some_file_name.mp3'
return response
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question