I have custom download function. When user clicks on download icon, first file is decrypted and then downloaded. This download icon is present in load component.
If decryption is successful, file is returned. If decryption fails, I want to show flash message that 'Download failed'.
Here is my custom download function:
def custom_download():
download_row = db(db.documents.id == request.args(0)).select().first()
download_file = download_row.file
# Name of file is table_name.field.XXXXX.ext, so retrieve original file name
org_file_name = db.documents.file.retrieve(download_file)[0]
file_header = "attachment; filename=" + org_file_name
response.headers['ContentType'] = "application/octet-stream"
response.headers['Content-Disposition'] = file_header
file_full_path = os.path.join(request.folder, 'uploads', download_file)
decrypted_file = decrypt_file(file_full_path)
if decrypted_file:
fh = open(decrypted_file, 'rb')
return response.stream(fh)
else:
return "Download Failed"
How can I trigger flash message in view from controller? Or any other way to tell user that download failed.