|
97 | 97 | ] |
98 | 98 | print("List files-", "\n", list_files) |
99 | 99 |
|
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("-------------------------------------") |
110 | 110 |
|
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 | + ) |
113 | 123 |
|
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) |
123 | 125 |
|
124 | | -print("Upload with url-------------", upload) |
| 126 | + with open("sample.jpg", mode="rb") as img: |
| 127 | + imgstr = base64.b64encode(img.read()) |
125 | 128 |
|
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 | + ) |
128 | 138 |
|
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) |
139 | 140 |
|
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") |
143 | 144 |
|
144 | | -print("-------------------------------------") |
| 145 | + print("-------------------------------------") |
145 | 146 |
|
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") |
151 | 152 |
|
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") |
154 | 155 |
|
155 | | -print("-------------------------------------") |
| 156 | + print("-------------------------------------") |
156 | 157 |
|
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") |
159 | 160 |
|
160 | | -print("-------------------------------------") |
161 | | -delete = imagekit.delete_file(list_files["response"][1]["fileId"],) |
| 161 | + print("-------------------------------------") |
| 162 | + delete = imagekit.delete_file(list_files["response"][1]["fileId"],) |
162 | 163 |
|
163 | | -print("Delete File-", delete) |
| 164 | + print("Delete File-", delete) |
164 | 165 |
|
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) |
168 | 169 |
|
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) |
171 | 172 |
|
172 | | -print("-------------------------------------") |
| 173 | + print("-------------------------------------") |
173 | 174 |
|
174 | | -print("Cache status-", purge_cache_status) |
| 175 | + print("Cache status-", purge_cache_status) |
175 | 176 |
|
176 | | -print("-------------------------------------") |
| 177 | + print("-------------------------------------") |
177 | 178 |
|
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) |
180 | 181 |
|
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 | + ) |
185 | 187 |
|
186 | | -print("-------------------------------------") |
| 188 | + print("-------------------------------------") |
187 | 189 |
|
188 | | -print("Bulk File delete-", imagekit.bulk_delete(bulk_ids)) |
| 190 | + print("Bulk File delete-", imagekit.bulk_delete(bulk_ids)) |
189 | 191 |
|
190 | | -print("-----------------------------") |
| 192 | + print("-----------------------------") |
191 | 193 |
|
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