Skip to content

Instantly share code, notes, and snippets.

@Kimjunkuk
Created January 4, 2022 01:39
Show Gist options
  • Select an option

  • Save Kimjunkuk/01182a027d05a17c988ec4f02f93be2f to your computer and use it in GitHub Desktop.

Select an option

Save Kimjunkuk/01182a027d05a17c988ec4f02f93be2f to your computer and use it in GitHub Desktop.
Uploading images to web server
#!/usr/bin/env python3
import requests, os
# The URL to upload the images
url="http://localhost/upload/"
# To get the username from environment variable
USER = os.getenv('USER')
# The directory which contains all the images.
image_directory='/home/{}/supplier-data/images/'.format(USER)
#Listing all the files in images directory
files=os.listdir(image_directory)
#Parsing through all the images
for image_name in files:
#Accepting files that has jpeg extension and ingnoring hidden files
if not image_name.startswith('.') and 'jpeg' in image_name:
#creating absolute path for each image
image_path=image_directory+image_name
#uploading jpeg files
with open(image_path, 'rb') as opened:
r = requests.post(url, files={'file': opened})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment