-1

I've a python-flask webapp which is deployed on Azure which serves as backend for a chatbot. Based on the user query, the bot performs an action and saves the file locally. This file needs to be shared to the user.

Is there a way that I can share a hyperlink to the user in chat for the user to download the file without having to create a storage on azure. (The file need not be stored and can be deleted after a timeout. File sizes are very small(10-20 kB))

Vijay
  • 1,030
  • 11
  • 34
  • If you're already able to save the file to a local directory... You can use a Flask endpoint to serve the file, e.g. using [send_from_directory](http://flask.pocoo.org/docs/0.12/api/#flask.send_from_directory). Would that work for you? – sytech Feb 26 '18 at 17:18

1 Answers1

0

You can serve a file with a Flask endpoint using send_from_directory

You could save the file with a name that is a hash or the file (or any unique naming convention), and use that as a link for users to use. Suppose you keep these files in the FILE_DIR directory.

from flask import request, send_from_directory

@app.route('/some-endpoint/')
def download_file():
    filename = request.args.get('hash')
    return send_from_directory(FILE_DIR, filename, as_attachment=True)
sytech
  • 29,298
  • 3
  • 45
  • 86
  • This is the way to go. Thought it's marked as a duplicate answer, I wanted to confirm that this method works on Azure app service to share files with user. – Vijay Mar 01 '18 at 04:14