Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save muthuspark/d1c0d567ac295a796b011a5d0fb33b4c to your computer and use it in GitHub Desktop.
Save muthuspark/d1c0d567ac295a796b011a5d0fb33b4c to your computer and use it in GitHub Desktop.
upload image from local file - python request
import os
import requests
img_to_upload = '/Users/muthukrishnan/Pictures/15566790261881556159500299IMG_20190330_120119.jpg'
url = "http://localhost:5000/api/document/page-extract"
uploaded_img_path = ''
with open(img_to_upload, 'rb') as img:
name_img = os.path.basename(img_to_upload)
files = {
'file': (name_img,img,'multipart/form-data', {'Expires': '0'})
}
with requests.Session() as s:
r = s.post(url,files=files)
uploaded_img_path = r.json()['image']
print(uploaded_img_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment