1

Is there a way to specify a download location in Django?

My page allows the user to

  • Click a button run to a EXE in the background
  • Then gives the user a new page where the download option is available
  • User clicks the download, and it downloads the latest file it generated

I read in a HTML post that you cannot force the browser to download a specific location. I am wondering if Django has an option that lets you do this.

def DownloadZip(request, zipname, prodVersID):
    print(zipname)
    zip_path = "C:/fbw/firmware/main/sys/" + zipname
    zip_file =  open(zip_path, 'rb')
    response = HttpResponse(zip_file, content_type='application/zip')
    response['Content-Disposition'] = 'attachment; filename=%s' %zipname
    response['Content-Length'] = os.path.getsize(zip_path)
    zip_file.close()

    return response
Community
  • 1
  • 1
JC203
  • 384
  • 7
  • 18

1 Answers1

0

After further research, I concluded that the reference post also reflects on Django. Django does not offer such feature, it is a security feature of the web browser that does not allow you to specify download location.

Credit to Darren

Whether the browser asks the user or not is down to the preferences in the browser.

You can't bypass those preference, otherwise it would violate user's security.

Community
  • 1
  • 1
JC203
  • 384
  • 7
  • 18