I have friends in this video.
We shall see how a file uploading operation is done in a flask application.
The applauding activity requires a very specific configuration of the ascherman for the form in return
investment.
There are different attributes that can be set to perform.
For example, we have already seen that there is a post attribute, then there is an action attribute.
There are two more attributes which must be specifically said in order to perform the upload operation.
One of the attributes is the IANSITI or encryption type.
It must be said to multiplatform data that is the prerequisite.
And secondly, the matter must be placed.
That means what the form would get as the method cannot be used for uploading a particular file.
So in order to upload the file, the material must be set to post and the IANSITI must be set to multiplatform
data.
These two are mandatory.
Next, the inside of the form.
Then there should be air input.
Time is equal to file.
That input type is equal to file will provide the user with a button to browse this file system so that
if you click on that button, he can select any file from the entire file system.
You can go to a particular driver folder or wherever, select a file and then there will be a submit
button, which if it is clicked, then the data will be posted using the post method to provide you
specific.
You are all that will be set as an action.
Now vendor up the submit button is clicked by the user.
The controller will go to the specify that you are in and the uploaded file will be transported or sealed
in a temporary location on the server.
It is for sale in the temporary location and then it is sold to its ultimate or final destination.
Now, the name of the file with which it is to be sealed can be hard coded.
You can give it in the form of a quotation on a string, but it is always recommended to obtain the
name from a request files, file, object, file, name, property of the request, files, file object
so that the same name that was present on the client's computer will be used as the name of the file
to be.
After uploading the file on the server, the name of their destination should be obtained from the request
object itself.
The recommended way, of course, is to obtain the secure version of the filename with the help of the
secure filename function and the secure filename function is defined in the work module that any way
will be installed or will be available when you import when you install the module itself.
So this line must be present at the top of your application for along with the other import that may
be necessary, define the part of the default upload folder.
The default upload folder can be preserved in the application configuration by the by the use of AP,
not config upload folder by default.
It is the root folder of the application, but you can send any other in a folder that you may want.
You can also set the maximum contained part.
That means what the maximum size of the file to be uploaded can also be set.
It is in the the parameter is to be provided in the bytes.
So these are all the parameters of all the specifications that you must take into account.
Now, this is the crux of the entire matter to be brought in or to be done in that in our practical
exercise, what the form this form must be provided in the e-mail template that you may render with
the help of insert a new function in which action is equal to where the actual uploading activity will
be done.
This is the real map to a particular view.
Function metrological to post is also necessary, but more importantly, IANSITI is equal to multiplatform
data that must be provided.
OK, then in order to let the user browse his computer and select the file, you have to use input type
equal to file and.
The other button that will present on the form will be submitted see that there are two buttons on the
form.
One is the browser button and there is the submit button.
Precisely for this purpose, the RNC type must be set to multipart.
So such a form will be rendered.
User will select a file, upload, submit the click the submit button.
The file data will be sent to the upload function inside the view function mapping with this uploader
you until you are to do this, find out the name of the file request on file file and then they have
the final say on the server with the help of the filename that is extracted from the request of you.
So this is the directory.
Did you see that there are three or four different activities to be performed.
So all these activities put together will be demonstrated to you in the example that is falling right
in front of you.
And so this is the Python script, which we will use to upload any selected file to the to our WRGA
server that we will start that the server will start running.
As soon as you start or execute this Python script, upload IRTPA.
So for that.
This is a very essential import that you must.
You know, we mentioned in our Python script at the beginning, you have to import the circular file
name function, which is defined in the work.
Module, which will be installed along with the flask module that you have to install to set up the
flask in orbit.
OK, so after doing all the required imports, you set up the flask application by declaring it, declaring
an object of the flask class.
This intuitively you have to do every time when you write a flask application in the rest of the protocol,
there are two.
You are rules that are defined, one examplar.
Which is my favorite word, python function upload.
And then there is a slash upload, a rule map to.
Uploader function.
The purpose of this absolute rule, that means the function, the function of the view, the purpose
of this view function abroad is to render a template applauded.
So this upload will must be present in the templates folder of your flask application.
What is then this uploader estimate file, it is it contains a multipart formula to.
A form with IANSITI, which is set to multi multipart and then there is a input pipe, is equal to five.
This is our Apollodorus G.M. in which this is a form.
This farm has one attribute called ACNC type, which is which must be said to multipart farm data whenever
you want.
The former.
To have a button which will browse your computer system to select a particular file, the IANSITI tribute
must be set to multipart oblique form data and the method also must be post.
In order to present a browser, a browser button.
In the form you should use, this input type is equal to file.
The name that is appearing on that button will be fired as soon as the this button name to file is clicked,
your Windows Explorer will be will be presented, allowing the user to select any desired file from.
Anywhere in the computer system, filesystem.
And then then there is a submit button, so this submit button, when it is pressed the selected file,
the data of the selected file will be.
Central to this at this are, which is a part of the action attributes, so action is equal to this.
You are.
This is, of course, the name of our server localhost 5000 uploader you are in.
Which is defined in our Python script to this you are in this file will be said.
Right.
So this is the Apollodorus, David.
Coming back to this, the uploader you are in.
And therefore, the map review function uploader.
What it does, it verifies whether the request method.
That means the data that is received by these uploader, Eurail is by this post, whether or not.
We are just seeing that in the upload estimate, the form has mythological to post, so this is true.
So the final data is obtained by ordering from brother request, not subject.
So every single request or files filed, so this will be the file object.
That must be saved, if not save, this file object has a function called the SEAL.
And this circular file name is a function in this work model which which will obtain the required destination
filename by have not filename.
So when this function will be successfully completed, the uploader function will return by return message
called file uploaded successfully, which which will be displayed on the browser.
This is, of course, the.
Uh, this run will start.
Our civil.
So it's a very fairly simple, straightforward activity, this will this upload auditioner will continue
a form with a file button and this uploader.
You are uploader function will save the.
File letter to.
The file name of the same name on the server so that we are to see now we're running this application.
So our Python script is named as uploader before we can start.
The sermon starts running.
And then you go back to the browser.
And Gildas, you are in the address bar localhost, 5000 oblique.
Upload, so as soon as hypocenter the.
You know, button, or rather the form with the brass button.
And a submit button will be displayed, so click on this brose.
Select any file that you want to upload on the server.
Uh.
So let us say.
I will open this file.
And based upon.
The selected filing will appear here.
Now, if I press on this submit button.
The uploader you are in will be used to send the final data and the upload function will save the file
later to.
If I live by thunder in the server folder.
So it responds with the file upload very successfully, will go to our.
Server destination and see whether the selected file has been, you know, uploaded there or not.
So there you see deep pathology, PGD was the name of the file that was selected by using the browser
button that is appearing in our flask application, which is the location of our.
Development support here.
So this is the.
Way in which the file upload activity can be performed.