-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
upload2bucket.py
39 lines (32 loc) · 1.09 KB
/
upload2bucket.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import ibm_boto3
from botocore.client import Config
credentials = {
'bucket': 'YOUR_BUCKET_NAME',
'iam_url': 'https://iam.ng.bluemix.net/oidc/token',
'resource_instance_id': 'YOUR_INSTANCE_ID',
'url': 'YOUR_REGION_ENDPOINT',
'api_key': 'YOUR_API_KEY'
}
image_directory = 'images'
annotations = '_annotations.json'
def main():
bucket = ibm_boto3.resource('s3',
ibm_api_key_id=credentials['api_key'],
ibm_service_instance_id=credentials['resource_instance_id'],
ibm_auth_endpoint=credentials['iam_url'],
config=Config(signature_version='oauth'),
endpoint_url=credentials['url']
).Bucket(credentials['bucket'])
print('uploading {}...'.format(annotations))
bucket.upload_file(annotations, annotations)
for filename in os.listdir(image_directory):
small = filename.lower()
if small.endswith('.jpeg') or small.endswith('.jpg') or small.endswith('.png'):
print('uploading {}...'.format(filename))
bucket.upload_file(os.path.join(image_directory, filename), filename)
continue
else:
continue
if __name__ == "__main__":
main()