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.

Revisions

  1. Kimjunkuk created this gist Jan 4, 2022.
    19 changes: 19 additions & 0 deletions example_upload.py
    Original 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})