Created
January 4, 2022 01:39
-
-
Save Kimjunkuk/01182a027d05a17c988ec4f02f93be2f to your computer and use it in GitHub Desktop.
Uploading images to web server
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 characters
| #!/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