1

I'd like to pick up a .csv file from local computer, from where python runs the server,

In my python file I currently got

elif msgdict.get("cmd") == "DOWNLOAD":
            #get the file from local drive, and send for opening/download

And then my html has the button and calls the javascript function:

<button id="btn_folder" type="button" class="btn btn-default" onclick="downloadFile()"><span class="glyphicon glyphicon-file"></span></button>

An my javascript:

function downloadFile()                 //This function will download the data
{
    var cmd = {"cmd":"DOWNLOAD"};
    ws_control.send(JSON.stringify(cmd));
    //The user should be able to download the file or the data should show up in another tab...
}

I'm very new to literally everything I am doing. I know how to open a file for read and write, but I don't know how to actually send the completed data over.

Lukali
  • 313
  • 2
  • 14
  • 1
    check this answer: https://stackoverflow.com/a/30043470/9050348 – maguri Aug 06 '18 at 14:37
  • @maguri would it be possible to use bottle to do this? I did find this: https://stackoverflow.com/questions/13725417/binary-file-download but I dont know where to put those lines.. Also at the top I am importing bottle as 'import bottle', would I still need 'from bottle import static_file'..? Can I place "@route('/download/') def download(filename): return static_file(filename, root='/path/to/static/files', download=filename) " right inside the python elif? – Lukali Aug 06 '18 at 14:50
  • I suppose you can, import it to your python backend controller and call it using ajax as the link posted on top.I think is a basic MVC call. not sure, sorry. – maguri Aug 06 '18 at 15:21

0 Answers0