python - Flask - Post a file with accompying JSON -


is possible post file flask app has both file , json data accompanying it?

in initial development, doing via 2 api endpoints, , seems clunky. i'd able accomplish using 1 post, instead of two.

is possible?

yes, can post file json data accompanying it. example:

import requests open(path_to_file, 'rb') my_file:         files = {'file': my_file}         payload = {'data1': 'foo', 'data2': 'bar'}         r = requests.post(data=payload, files=files) 

there lot of useful information regarding flask , requests (a nice http lib) here:

  1. http://flask.pocoo.org/docs/0.10/quickstart/#quickstart
  2. http://docs.python-requests.org/en/latest/user/quickstart/

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -