Bivek Gyawali
Bivek Gyawali

Reputation: 136

How can I upload files in Postman?

I want to pass images through POST method in POSTMAN but I get None type response in the line request.files['image']

I have tried a number of different things but I am not able to solve the problem.

from flask import Flask,jsonify
from flask import request
import face_recognition
import json

app = Flask(__name__)

@app.route('/')
def index():
   return ''


@app.route('/valid_faces', methods=['POST'])


def POST():
    if request.method == 'POST':

    # getting the images url from the request
    print('....')
    name1 = request.files['file'] if request.files.get('file') else None
    print('....')
    print (name1)        # name2 = request.form.get('name2')

    # map the url to the ones in the folder images
    firstImage = name1


    # loading the image inside a variable
    firstImage = face_recognition.load_image_file(firstImage)




    result=face_recognition.face_locations(firstImage)


    if result:
        # x={'valid_faces':True}
        # return jsonify(x)
        return "True"
    else:
        # x={'valid_faces':False}
        # return jsonify(x)
        return "False"


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

Upvotes: 4

Views: 7501

Answers (5)

Khanbala Rashidov
Khanbala Rashidov

Reputation: 102

you can do it

 files = request.files.getlist("file")

Upvotes: 0

cedric
cedric

Reputation: 367

follow this process: https://i.sstatic.net/GGm4I.png

  • Set Method to POST
  • Change body tab to form-data
  • Set key
  • in Value, hover, you can see file/text. in here select file
  • Select file you want to upload.
  • Send request.

Upvotes: 2

Arkadit Vinokurov
Arkadit Vinokurov

Reputation: 31

In Postman, do the following:

  • Set the method to POST
  • Set the body type to form-data
  • Establish Key/Value pairs for input. Set the value for the Key to "file"
  • Mouse over the Key field and choose Text or File from the drop-down menu
  • Click Send to process the request

Upvotes: 3

Bhramari
Bhramari

Reputation: 11

In my case Postman set empty first value for FileStorage object in request.files . You can check this using:

print(str(request.files))

And in case of empty index instead

file = request.files['file']

try to use

file = request.files['']

Upvotes: 0

zkdev
zkdev

Reputation: 315

If you wish to append a file to a postman call it needs to be added to the body. Check form-data and select file instead of text. You can now select a file with the windows file explorer.

To obtain the given file use the request package.

file = request.files['file']

The index has to be the same string you specified within the postman body data.

Upvotes: 8

Related Questions