blob-upload-2_4.py 713 B

123456789101112
  1. def upload_image(self, file_name):
  2. # Create blob with same name as local file name
  3. blob_client = self.blob_service_client.get_blob_client(container=MY_IMAGE_CONTAINER,
  4. blob=file_name)
  5. # Get full path to the file
  6. upload_file_path = os.path.join(LOCAL_IMAGE_PATH, file_name)
  7. # Create blob on storage
  8. # Overwrite if it already exists!
  9. image_content_setting = ContentSettings(content_type='image/jpeg')
  10. print(f"uploading file - {file_name}")
  11. with open(upload_file_path, "rb") as data:
  12. blob_client.upload_blob(data, overwrite=True, content_settings=image_content_setting)