Python flask download a file on submit






















Connect and share knowledge within a single location that is structured and easy to search. I'm trying to write a really simply webapp with PythonAnywhere and Flask that has lets the user upload a text file, generates a csv file, then lets the user download the csv file. It doesn't have to be fancy, it only has to work. I have already written the program for generating the csv from a txt file on the drive. I don't know how to do this.

How should I structure this program? I would prefer to work on the files wihthout saving them anywhere but if I have to save them to the PythonAnywhere directory, I could. How can I do that? PythonAnywhere dev here. This is a good question about Flask and web development in general rather than specific to our system, so I'll try to give a generic answer without anything specific to us There are a few things that I'd need to know to give a definitive answer to your question, so I'll start by listing the assumptions I'm making -- leave me a comment if I'm wrong with any of them and I'll update the answer appropriately.

If both of those are the case, then the best way to structure your Flask app would be to handle everything inside Flask. There's a live version of this app on PythonAnywhere here. If you don't add the content type, FF If you don't add Cache-Control your result may get cached, and if you serve active content this is not what you want. If you use must-revalidate with no age, it will effectively serve as no-cache - see here and here for an explanation.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Only with successful operation it will send response status otherwise it will send bad request with error message. If you want to change the port then you can change the line app. I will test our application using Postman tool.

You may also do client side programming to call the above REST endpoint and upload the file. Your email address will not be published. Roy Tutorials Technical… Theoretical… Practical….

When you select a file for upload: you can select only the specified types of files as in the main. Thanks fo sharing the article.

I have saved the app. Your article says save it under Flask, but where do I find that? This only works with a HTML form — how can you correct this so you can call it from any external client, ex postman?

Hi, Thanks for posting this solution. I am trying to create a python web app in VS using this code. I have installed flask and werkzeug but I am getting an error on the import urllib. Do you have any advice on how to resolve this please? Many thanks! Thanks a lot for the detailed instructions. I am getting a error though when submitting the request. Any idea how to resolve this? Please check your are posting request through correct http method that is defined on your server side.

Thanks for pointing out. Yes this is for uploading single file. I will post soon on how to upload multiple files.



0コメント

  • 1000 / 1000