Hi,
I am working on downloading a ZIP folder. My code is currently capable of downloading the ZIP folder directly to my system’s Downloads folder silently. However, I want to see the download progress in the browser and have it appear in the browser’s Downloads section.
How can I achieve this?
this is my code in routes.py
import os
from trytond.wsgi import app
from trytond.pool import Pool
from werkzeug.wrappers import Response
@app.route('/files_export/download/<int:id>', methods=['GET'])
def download_files_export(id):
'''
Tryton web endpoint to serve the ZIP file download.
'''
FilesExportStart = Pool().get('account.files.export.start')
record = FilesExportStart(id)
zip_path = record.generate_files_and_zip()
if not os.path.exists(zip_path):
return Response('ZIP file not found. Please generate it first.', status=404)
with open(zip_path, 'rb') as f:
data = f.read()
response = Response(data, content_type='application/zip')
response.headers['Content-Disposition'] = f'attachment; filename={os.path.basename(zip_path)}'
return response
and in init ,8 I have called this file like that
from . import routes
__all__ = ['register', 'routes']
But nothing happen, it seems like the function download_files_export(id)
is not called l.
any help will. be appreciated