Werkzeug File Uploads
I have been meaning to write about how to implement werkzeug file uploads before how to do file uploads with TurboGears because this is the top search engine query that my visitors are coming from and the fact that they cannot find what they search on my blog is really bothering me so here it is.
The same logic like the TurboGears version applies to Werkzeug. The only difference is that Werkzeug doesn't store the files within the request.params or request.form but it stores the files in request.files as FieldStorage.
- We will start by creating our model.
- After model, we will create our form.
- And we will create action in order to access the file name and file content via request.files and we will save the file to database.
- We will display the file.
If you read the code carefully you will see there is a function that I have used named "secure_filename". This method simply returns a secure filename so you can store the file safely in your file system. This is actually for the files that you will be saving to your file system.
If you wonder how you can save uploaded files to your database, you can simply use the save method.
Hope this post helps some of you out and I can feel better now. Leave your comments and have your say.

Comments
Leave a Response