How To Send Video Files To Flask API Using Postman?

Hello Learners…

Welcome to my blog…

Here we learn how to send our video files to flask API using Postman for further processing.

Table Of Content:

  • Introduction
  • How To Send Video Files To Flask API Using Postman?
  • Send MP4 file to Flask API using postman
  • Summary

Introduction:

In this post, we implement some methods to send our video files to Flask API from postman. using this method we can send our video files like .mp4 or .mkv to Flask API and see the response of our Flask API.it is used to test our Flask API using postman before our API goes on the production server.it is good practice to try our API using postman.

How To Send Video Files To Flask API Using Postman?

  • Send mp4 file to Flask API using postman

Send MP4 file to Flask API using postman

First, we have to create a Flask API. For this, we need to install Flask using pip.

pip install flask

Here is the python code for the create a Flask API. This code works only for mp4 files.

Create a file app.py and add the below code into that file.

from flask import Flask,request

app=Flask(__name__)

@app.route("/",methods=["POST","GET"])
def main():
    try:
        if request.method=='POST':
     
            video=request.files['video']
            video_name=video.filename

            if '.mp4' in video_name:                
                video.save(video_name)

                return {"response":"file saved successfully in your current durectory"}
            else:
                return {"error":"select you mp4 file"}
    except Exception as e:
        return {"error":str(e)}

if __name__=="__main__":
    app.run("0.0.0.0",debug=True)

Run the app.py file using the command:

python3 app.py

We get an URL http://localhost:5000/

Now open our postman and send a POST request as below.

Select POST request And then Body > form-data.

screenshot by the author

Now we have to select our mp4 files, click on the select files option and select our mp4 file.

screenshot by the author

Here, We can see the response of our Flask API.

Our MP4 file is stored in the current directory where our app.py is located, we can find our file there. and use that file for further processing.

Continue…

Summary:

Happy Learning And Keep Learning…

Thank You…

Also, you can read

Posted by the author
Posted by the author

References:

2 thoughts on “How To Send Video Files To Flask API Using Postman?”

Leave a Comment