forked from vsahni3/HTV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_url_test.py
More file actions
30 lines (21 loc) · 821 Bytes
/
image_url_test.py
File metadata and controls
30 lines (21 loc) · 821 Bytes
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
"""Example code for uploading images to image URL."""
import requests
def get_image_url(picture_path: str) -> str:
"""
Given a file path, upload it to the cloud and then return the image URL corresponding to that image.
Preconditions:
- picture_path leads to a valid image picture
- picture_path[-3:] == 'jpg'
"""
# API key
headers = {
'Content-Type': 'image/jpeg',
'Authorization': 'Bearer public_kW15ax2CzFC2twZcwg849iMndxSY',
}
# put picture location here
with open(picture_path, 'rb') as f:
data = f.read()
response = requests.post('https://api.upload.io/v2/accounts/kW15ax2/uploads/binary', headers=headers, data=data)
return response.json()["fileUrl"]
# TESTING FUNCTION HERE
# print(get_image_url('test_pictures/palm-tree.jpg'))