-1

sending a file through a curl command or postman

I am trying to upload image to my Flask app, I was able to sucesffuly do that through a web browser upload button, however when I do a POST request from my postman if it giving me a error 303

127.0.0.1 - - [2017-03-28 20:16:05] "POST /api/user/uploadimg/ HTTP/1.1" 302 632 0.005147

here is my Flask code

@app.route('/api/user/uploadimg/', methods=['POST','GET'])
def upload_file():
    def allowed_file(filename):
        return '.' in filename and \
            filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
    # check if the post request has the file part

    if request.method == 'POST':
    # check if the post request has the file part
    if 'file' not in request.files:
        flash('No file part')
        return jsonify({"Nope":"No file entered"})
    file = request.files['file']
    # if user does not select file, browser also
    # submit a empty part without filename
    if file.filename == '':
        flash('No selected file')
        return redirect(request.url)
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        user=User.query.get(7)
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        user.image_filename=filename
        user.image_url=url_for(url_for('uploaded_file',filename=filename))
        db.session.commit()
        return jsonify({"Done":"All set!"})
    return '''
        <!doctype html>
        <title>Upload new File</title>
        <h1>Upload new File</h1>
        <form method=post enctype=multipart/form-data>
        <p><input type=file name=file>
        <input type=submit value=Upload>
        </form>'''

I would love to know how can I curl the following url and send the file using a curl or postman. PS: I have postman sending the command as POST method, and the content type is multipart-data

Here is the curl command I am using to send data

curl -X POST -F "file=certificate.pdf" http://localhost:3500/api/user/uploadimg/ -H "Content-Type: multiform/form-data"
0

1 Answer 1

2

Fixed it, in postman when sending multiform data, the value for Content type does not have to be specified. I have no idea how to do it with curl command.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.