Thursday, 9 May 2019

Server-side python returning a zip file for a download

Using my client I pass a parameter by get to a python script on the server, it runs a process and creates a zip file. In my client side JavaScript my ajax call just tells me it was able to pass the data to my python script.

I've tried sys.stdout.write(b"zipfilename") but nothing happens. If I can't pass the file back, is there a way to pass something back so my JavaScript knows it's done? I'm not using NODE or Angular. My python script does run and creates the zip file on the server but the JavaScript page doesn't know it nor does a download dialog appear. I'm missing something basic but I can't find it.

My JS AJAX call:

  $.ajax({
       url: theUrl,
       type: 'get',
       success: function(response){

       }      });

The end of my python script:

def createZip(v, charset=None):

    with ZipFile(v +'.zip', 'w') as myzip:
        myzip.write(v +'.shp')
        myzip.write(v +'.shx')
        myzip.write(v +'.dbf')
        myzip.write(v +'.prj')

    return 'c:/dev/python/'+ v + '.zip'

createZip(fn)



from Server-side python returning a zip file for a download

No comments:

Post a Comment