Merge remote-tracking branch 'sourya/master'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents 818c42c, a6ea633 · Browse files · 1 file·+11 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+11 added−15 removed
- other:+11 added−15 removed
Provenance
- Commit
9a61e7d- Tree
e997b5a- Author
Markus Unterwaditzer <markus@unterwaditzer.net>- Committer
Markus Unterwaditzer <markus@unterwaditzer.net>- Parent 1
818c42c- Parent 2
a6ea633
1 file changed+11 added−15 removed
modified:docs/patterns/fileuploads.rst+11 added-15 removed
31 unmodified lines32 33 So first we need a couple of imports. Most should be straightforward, the34 :func:`werkzeug.secure_filename` is explained a little bit later. The35 ``UPLOAD_FOLDER`` is where we will store the uploaded files and the36-``ALLOWED_EXTENSIONS`` is the set of allowed file extensions. Then we add a37-URL rule by hand to the application. Now usually we're not doing that, so38-why here? The reasons is that we want the webserver (or our development39-server) to serve these files for us and so we only need a rule to generate40-the URL to these files.36+``ALLOWED_EXTENSIONS`` is the set of allowed file extensions.37 38 Why do we limit the extensions that are allowed? You probably don't want39 your users to be able to upload everything there if the server is directly40 sending out the data to the client. That way you can make sure that users62 unmodified lines103 104 >>> secure_filename('../../../../home/username/.bashrc')105 'home_username_.bashrc'106 111-Now one last thing is missing: the serving of the uploaded files. As of112-Flask 0.5 we can use a function that does that for us::107+Now one last thing is missing: the serving of the uploaded files. In the 108+:func:`upload_file()` we redirect the user to 109+``url_for('uploaded_file', filename=filename)``, that is, ``/uploads/filename``. 110+So we write the :func:`uploaded_file` function to return the file of that name. As111+of Flask 0.5 we can use a function that does that for us::112 113 from flask import send_from_directory114 115 @app.route('/uploads/<filename>')51 unmodified lines167 client asks the server every 5 seconds how much it has transmitted168 already. Do you realize the irony? The client is asking for something it169 should already know.170 172-Now there are better solutions to that work faster and more reliable. The173-web changed a lot lately and you can use HTML5, Java, Silverlight or Flash174-to get a nicer uploading experience on the client side. Look at the175-following libraries for some nice examples how to do that:171+Now there are better solutions that work faster and are more reliable. There 172+are JavaScript libraries like jQuery (http://jQuery.com) that have form plugins 173+to ease the construction of progress bar. Another great option is dropzone.js 174+(http://www.dropzonejs.com) that allows users to drag and drop files on to the 175+page.176 177-- `Plupload <http://www.plupload.com/>`_ - HTML5, Java, Flash178-- `SWFUpload <http://www.swfupload.org/>`_ - Flash179-- `JumpLoader <http://jumploader.com/>`_ - Java177 181-178 An Easier Solution179 ------------------180 181 Because the common pattern for file uploads exists almost unchanged in all5 unmodified lines