1

I have one file stored in google drive which I download using:

url = 'https://docs.google.com/spreadsheets/d/ID/edit?usp=sharing'
output = 'file.xlsx'
gdown.download(url, output, quiet=False)

My goal is to make that file downloadable in a html file through a button using Google Drive as a backend. Is there any way to do that?

Summarizing: Some user open an html file where there's a button to download some file placed in my drive.

the flask template I am thinking to use looks like:

from flask import Flask, Response
app = Flask(__name__)

@app.route("/")
def hello():
    return '''
        <html><body>
        Hello. <a href="/getPlotCSV">Click me.</a>
        </body></html>
        '''

@app.route("/getPlotCSV")
def getPlotCSV():
    # with open("outputs/Adjacency.csv") as fp:
    #     csv = fp.read()
    excel = '1,2,3\n4,5,6\n'
    return Response(
        excel,
        mimetype="xlsx",
        headers={"Content-disposition":
                 "attachment; filename=file.xlsx"})

EDIT:

I mapped my html button with """<form action={url}> <input type=submit value=Go to Google/></form>"""

but it takes me directly to the spreadsheet in google sheets. How do I assign an action to that button so that the file is downloaded locally to the user?

Lash
  • 333
  • 1
  • 2
  • 14
  • If the file must be downloaded only after authentication from your UI you need to stream it from your backend. Else you can create a public access url and map it to the button – Kris Oct 31 '21 at 18:31
  • I have a public url. See my edit. I mapped my html button to that url, but I want to assign an action to that button in order to download the file . THanks – Lash Oct 31 '21 at 18:49
  • Does this answer your question? [How to trigger a file download when clicking an HTML button or JavaScript](https://stackoverflow.com/questions/11620698/how-to-trigger-a-file-download-when-clicking-an-html-button-or-javascript) – Kris Nov 01 '21 at 09:57

0 Answers0