Python flask on downloading zip file gets corrupted


Python flask on downloading zip file gets corrupted



I have written following python flask code to download zip file.


@ns.route('/zip_file_download', strict_slashes=False)
class ZipDownload(Resource):
def get(self):
output_path = os.path.abspath(os.path.join(os.getcwd(), './out'))
out_file_name = os.path.join(output_path, 'sample.zip')
r = send_file(out_file_name, mimetype='application/octet-stream',
attachment_filename='sample.zip', as_attachment=True)
return r



This downloads the zip file but on extracting the zip file it gives an error - Error - 21 - is not a directory - Unable to expand probably because it gets corrupted. I also tried with send_from_directory but the same error crept there too. I am developing this on Mac machine but the downloaded files are also corrupted when opened on windows or an other OS. Any suggestions?



PS: Moreover, this issue is only happening when running the API from a Mac machine. Things seem to be fine when ran from windows on linux machine. It's quite peculiar.





Found this on web: pythonprogramming.net/flask-send-file-tutorial have you tried that?
– Fábio Correia
Jun 27 at 12:40






Your code seems to be correct. The only reason you are getting a faulty .zip is either its corrupt from source, or there is something wrong in your path (out_file_name). Use print() function to print the path on the console before sending the response, and check whether its correct.
– Prahlad Yeri
Jun 27 at 23:29


out_file_name


print()





The path is correct. I have already checked that. Also the file at the source is correct. Moreover, this issue is only happening when running the API from a Mac machine. Things seem to be fine when ran from windows on linux machine. It's quite peculiar.
– Ujjwal Upadhyay
Jun 29 at 10:25









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift