![Upload images by form with FTP in Flask (Python)](/img/articleImages/upload-images-by-form-ftp-in-flask.jpg)
Upload images by form with FTP in Flask (Python)
![Original YouTube Logo](/img/original-youtube-logo.png)
Article have related YouTube video
Sending images via a form using FTP in Flask is thanks to ftplib a pretty simple task. In this article i will show you an example on how to send an image to your server using FTP.
So thanks to the ftp library ftplib, we can in Python upload images to our server very easy. All you need to know is your FTP host name, FTP username and your FTP password.
This '/upload_image' route should be set inside your app.py or wherever you have your routes.
By saying request.files['image'] you get the image from the form. After that it create an instance of a FTP object starting by defining the host name. Then moves on to get the login/credentials, the path to where you want the image to go (cwd, current working directory). And finally before quiting the upload, it handles the binary process of storing the image on the server.
Now that your method for handling the FTP request is setup, you can go and make the form in the template you would like to.
The form calls the upload_image url/route with a POST request that have the enctype of multipart/form-data. The to input fields are the image upload button and the submit button.