Created
January 4, 2022 01:39
-
-
Save Kimjunkuk/01182a027d05a17c988ec4f02f93be2f to your computer and use it in GitHub Desktop.
Revisions
-
Kimjunkuk created this gist
Jan 4, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ #!/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})