Skip to content

Commit 9c3e67d

Browse files
committed
feat: add sdk version to url
1 parent ec7d1fa commit 9c3e67d

File tree

3 files changed

+77
-71
lines changed

3 files changed

+77
-71
lines changed

imagekitio/constants/defaults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ class Default(enum.Enum):
99
QUERY_TRANSFORMATION_POSITION,
1010
]
1111
DEFAULT_TIMESTAMP = "9999999999"
12-
SDK_VERSION_PARAM = "python-1.0.0"
12+
SDK_VERSION = "python-1.0.0"

imagekitio/url.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ def build_url(self, options: dict) -> str:
128128
generated_url = urlunparse(
129129
result_url_dict.get(f, "") for f in ParseResult._fields
130130
)
131+
if result_url_dict["query"]:
132+
generated_url = generated_url + "&sdk-version=" + Default.SDK_VERSION.value
133+
else:
134+
generated_url = generated_url + "?sdk-version=" + Default.SDK_VERSION.value
131135
return generated_url
132136

133137
@staticmethod

sample/sample.py

Lines changed: 72 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -97,97 +97,99 @@
9797
]
9898
print("List files-", "\n", list_files)
9999

100-
upload = imagekit.upload(
101-
file=open("sample.jpg", "rb"),
102-
file_name="testing",
103-
options={
104-
"response_fields": ["is_private_file", "tags"],
105-
"tags": ["abc", "def"],
106-
"use_unique_file_name": False,
107-
},
108-
)
109-
print("-------------------------------------")
100+
upload = imagekit.upload(
101+
file=open("sample.jpg", "rb"),
102+
file_name="testing",
103+
options={
104+
"response_fields": ["is_private_file", "tags"],
105+
"tags": ["abc", "def"],
106+
"use_unique_file_name": False,
107+
},
108+
)
109+
print("-------------------------------------")
110110

111-
print("Upload with binary-", upload, end="\n\n")
112-
file_id = upload["response"]["fileId"]
111+
print("Upload with binary-", upload, end="\n\n")
112+
file_id = upload["response"]["fileId"]
113+
114+
upload = imagekit.upload(
115+
file=url,
116+
file_name="testing",
117+
options={
118+
"response_fields": ["is_private_file"],
119+
"is_private_file": True,
120+
"tags": ["abc", "def"],
121+
},
122+
)
113123

114-
upload = imagekit.upload(
115-
file=url,
116-
file_name="testing",
117-
options={
118-
"response_fields": ["is_private_file"],
119-
"is_private_file": True,
120-
"tags": ["abc", "def"],
121-
},
122-
)
124+
print("Upload with url-------------", upload)
123125

124-
print("Upload with url-------------", upload)
126+
with open("sample.jpg", mode="rb") as img:
127+
imgstr = base64.b64encode(img.read())
125128

126-
with open("sample.jpg", mode="rb") as img:
127-
imgstr = base64.b64encode(img.read())
129+
upload_base64 = imagekit.upload(
130+
file=imgstr,
131+
file_name="test64",
132+
options={
133+
"response_fields": ["is_private_file", "metadata", "tags"],
134+
"is_private_file": True,
135+
"tags": ["abc", "def"],
136+
},
137+
)
128138

129-
upload_base64 = imagekit.upload(
130-
file=imgstr,
131-
file_name="test64",
132-
options={
133-
"response_fields": ["is_private_file", "metadata", "tags"],
134-
"is_private_file": True,
135-
"tags": ["abc", "def"],
136-
},
137-
)
138-
print("Upload base64", upload_base64)
139+
print("Upload base64", upload_base64)
139140

140-
url_uploaded_id = upload["response"]["fileId"]
141-
image_url = upload["response"]["url"]
142-
print("Upload with url -", upload, "\n\n")
141+
url_uploaded_id = upload["response"]["fileId"]
142+
image_url = upload["response"]["url"]
143+
print("Upload with url -", upload, "\n\n")
143144

144-
print("-------------------------------------")
145+
print("-------------------------------------")
145146

146-
updated_detail = imagekit.update_file_details(
147-
list_files["response"][0]["fileId"],
148-
{"tags": ["image_tag"], "custom_coordinates": "10,10,100,100"},
149-
)
150-
print("Updated detail-", updated_detail, end="\n\n")
147+
updated_detail = imagekit.update_file_details(
148+
list_files["response"][0]["fileId"],
149+
{"tags": ["image_tag"], "custom_coordinates": "10,10,100,100"},
150+
)
151+
print("Updated detail-", updated_detail, end="\n\n")
151152

152-
details = imagekit.get_file_details(url_uploaded_id)
153-
print("File detail with binary upload-", details, end="\n\n")
153+
details = imagekit.get_file_details(url_uploaded_id)
154+
print("File detail with binary upload-", details, end="\n\n")
154155

155-
print("-------------------------------------")
156+
print("-------------------------------------")
156157

157-
details = imagekit.get_file_details(upload["response"]["fileId"])
158-
print("File detail with url upload-", details, end="\n\n")
158+
details = imagekit.get_file_details(upload["response"]["fileId"])
159+
print("File detail with url upload-", details, end="\n\n")
159160

160-
print("-------------------------------------")
161-
delete = imagekit.delete_file(list_files["response"][1]["fileId"],)
161+
print("-------------------------------------")
162+
delete = imagekit.delete_file(list_files["response"][1]["fileId"],)
162163

163-
print("Delete File-", delete)
164+
print("Delete File-", delete)
164165

165-
print("-------------------------------------")
166-
purge_cache = imagekit.purge_cache(file_url=image_url)
167-
print("Purge cache-", purge_cache)
166+
print("-------------------------------------")
167+
purge_cache = imagekit.purge_cache(file_url=image_url)
168+
print("Purge cache-", purge_cache)
168169

169-
request_id = purge_cache["response"]["request_id"]
170-
purge_cache_status = imagekit.get_purge_cache_status(request_id)
170+
request_id = purge_cache["response"]["request_id"]
171+
purge_cache_status = imagekit.get_purge_cache_status(request_id)
171172

172-
print("-------------------------------------")
173+
print("-------------------------------------")
173174

174-
print("Cache status-", purge_cache_status)
175+
print("Cache status-", purge_cache_status)
175176

176-
print("-------------------------------------")
177+
print("-------------------------------------")
177178

178-
auth_params = imagekit.get_authentication_parameters()
179-
print("Auth params-", auth_params)
179+
auth_params = imagekit.get_authentication_parameters()
180+
print("Auth params-", auth_params)
180181

181-
print("-------------------------------------")
182-
print(
183-
"Phash distance-", imagekit.phash_distance("f06830ca9f1e3e90", "f06830ca9f1e3e90"),
184-
)
182+
print("-------------------------------------")
183+
print(
184+
"Phash distance-",
185+
imagekit.phash_distance("f06830ca9f1e3e90", "f06830ca9f1e3e90"),
186+
)
185187

186-
print("-------------------------------------")
188+
print("-------------------------------------")
187189

188-
print("Bulk File delete-", imagekit.bulk_delete(bulk_ids))
190+
print("Bulk File delete-", imagekit.bulk_delete(bulk_ids))
189191

190-
print("-----------------------------")
192+
print("-----------------------------")
191193

192-
remote_file_url = upload["response"]["url"]
193-
print("Get metadata-", imagekit.get_remote_url_metadata(remote_file_url))
194+
remote_file_url = upload["response"]["url"]
195+
print("Get metadata-", imagekit.get_remote_url_metadata(remote_file_url))

0 commit comments

Comments
 (0)