Skip to content

Commit 41f56be

Browse files
Manu ChaudharyManu Chaudhary
authored andcommitted
Test case update
1 parent 2dff6ea commit 41f56be

File tree

2 files changed

+10
-181
lines changed

2 files changed

+10
-181
lines changed

README.md

Lines changed: 6 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,7 @@ transformation code from ImageKit docs as the name when using in the ```url``` f
235235
The SDK provides a simple interface using the `.upload()` method to upload files to the ImageKit Media library. It
236236
accepts all the parameters supported by the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload).
237237

238-
The `upload()` method requires at least the `file` and the `file_name` parameter to upload a file and returns
239-
a callback with the `error` and `result` as arguments. You can pass other parameters supported by the
240-
ImageKit upload API using the same parameter name as specified in the upload API documentation. For example, to
238+
The `upload()` method requires at least the `file` and the `file_name` parameter to upload a file. You can pass other parameters supported by the ImageKit upload API using the same parameter name as specified in the upload API documentation. For example, to
241239
specify tags for a file at the time of upload use the tags parameter as specified in the
242240
[documentation here](https://docs.imagekit.io/media-library/overview/image-tags)
243241

@@ -247,184 +245,15 @@ Simple usage
247245
```python
248246
imagekit.file_upload(
249247
file = "<url|base_64|binary>", # required
250-
file_name= "my_file_name.jpg" # required
248+
file_name= "my_file_name.jpg", # required
249+
folder : "/example-folder/",
250+
tags: ["sample-tag"]
251251
)
252252

253253
```
254-
## Available options for request
255254

256-
<table class="table-0f56c2d8" data-key="12024">
257-
258-
<tbody>
259-
260-
<tr class="tableRow-41a0302b" data-key="11680">
261-
262-
<td data-table="cell" class="tableCell-150ac604" data-key="11676" style="text-align: left;">
263-
264-
<span class="text-4505230f--UIH400-4e41e82a--textContentFamily-49a318e1"><span data-key="11674"><span data-offset-key="11674:0">Parameter</span></span></span>
265-
266-
</td>
267-
268-
<td data-table="cell" class="tableCell-150ac604" data-key="11679" style="text-align: left;">
269-
270-
<span class="text-4505230f--UIH400-4e41e82a--textContentFamily-49a318e1"><span data-key="11677"><span data-offset-key="11677:0">Description</span></span></span>
271-
272-
</td>
273-
274-
</tr>
275-
276-
<tr class="tableRow-41a0302b" data-key="11724">
277-
278-
<td data-table="cell" class="tableCell-150ac604" data-key="11697" style="text-align: left;">
279-
280-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="11681"><span data-offset-key="11681:0">**file**</span> <span data-offset-key="11681:1">required</span></span></span>
281-
282-
</td>
283-
284-
<td data-table="cell" class="tableCell-150ac604" data-key="11723" style="text-align: left;">
285-
286-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="11698"><span data-offset-key="11698:0">This field accepts three kinds of values: -</span> <span data-offset-key="11698:1">`binary`</span> <span data-offset-key="11698:2">- You can send the content of the file as binary. This is used when a file is being uploaded from the browser. -</span> <span data-offset-key="11698:3">`base64`</span> <span data-offset-key="11698:4">- Base64 encoded string of file content. -</span> <span data-offset-key="11698:5">`url`</span> <span data-offset-key="11698:6">- URL of the file from where to download the content before uploading. Downloading file from URL might take longer, so it is recommended that you pass the binary or base64 content of the file. Pass the full URL, for example -</span> <span data-offset-key="11698:7">`https://www.example.com/rest-of-the-image-path.jpg`</span><span data-offset-key="11698:8">.</span></span></span>
287-
288-
</td>
289-
290-
</tr>
291-
292-
<tr class="tableRow-41a0302b" data-key="11742">
293-
294-
<td data-table="cell" class="tableCell-150ac604" data-key="11738" style="text-align: left;">
295-
296-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="11725"><span data-offset-key="11725:0">**file_name**</span> <span data-offset-key="11725:1">required</span></span></span>
297-
298-
</td>
299-
300-
<td data-table="cell" class="tableCell-150ac604" data-key="11741" style="text-align: left;">
301-
302-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="11739"><span data-offset-key="11739:0">The name with which the file has to be uploaded.</span></span></span>
303-
304-
</td>
305-
306-
</tr>
307-
308-
<tr class="tableRow-41a0302b" data-key="11792">
309-
310-
<td data-table="cell" class="tableCell-150ac604" data-key="11756" style="text-align: left;">
311-
312-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="11743"><span data-offset-key="11743:0">**use_unique_file_name**</span> <span data-offset-key="11743:1">optional</span></span></span>
313-
314-
</td>
315-
316-
<td data-table="cell" class="tableCell-150ac604" data-key="11791" style="text-align: left;">
317-
318-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="11757"><span data-offset-key="11757:0">Whether to use a unique filename for this file or not. - Accepts</span> <span data-offset-key="11757:1">`true`</span> <span data-offset-key="11757:2">or</span> <span data-offset-key="11757:3">`false`</span><span data-offset-key="11757:4">. - If set</span> <span data-offset-key="11757:5">`true`</span><span data-offset-key="11757:6">, ImageKit.io will add a unique suffix to the filename parameter to get a unique filename. - If set</span> <span data-offset-key="11757:7">`false`</span><span data-offset-key="11757:8">, then the image is uploaded with the provided filename parameter and any existing file with the same name is replaced.</span> <span data-offset-key="11757:9">**Default value**</span> <span data-offset-key="11757:10">-</span> <span data-offset-key="11757:11">`true`</span></span></span>
319-
320-
</td>
321-
322-
</tr>
323-
324-
<tr class="tableRow-41a0302b" data-key="11837">
325-
326-
<td data-table="cell" class="tableCell-150ac604" data-key="11809" style="text-align: left;">
327-
328-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="11793"><span data-offset-key="11793:0">**tags**</span> <span data-offset-key="11793:1">optional</span></span></span>
329-
330-
</td>
331-
332-
<td data-table="cell" class="tableCell-150ac604" data-key="11836" style="text-align: left;">
333-
334-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="11810"><span data-offset-key="11810:0">Set the tags while uploading the file. - Comma-separated value of tags in format</span> <span data-offset-key="11810:1">`tag1,tag2,tag3`</span><span data-offset-key="11810:2">. For example -</span> <span data-offset-key="11810:3">`t-shirt,round-neck,men`</span> <span data-offset-key="11810:4">- The maximum length of all characters should not exceed 500. -</span> <span data-offset-key="11810:5">`%`</span> <span data-offset-key="11810:6">is not allowed. - If this field is not specified and the file is overwritten then the tags will be removed.</span></span></span>
335-
336-
</td>
337-
338-
</tr>
339-
340-
<tr class="tableRow-41a0302b" data-key="11900">
341-
342-
<td data-table="cell" class="tableCell-150ac604" data-key="11854" style="text-align: left;">
343-
344-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="11838"><span data-offset-key="11838:0">**folder**</span> <span data-offset-key="11838:1">optional</span></span></span>
345-
346-
</td>
347-
348-
<td data-table="cell" class="tableCell-150ac604" data-key="11899" style="text-align: left;">
349-
350-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="11855"><span data-offset-key="11855:0">The folder path (e.g.</span> <span data-offset-key="11855:1">`/images/folder/`</span><span data-offset-key="11855:2">) in which the image has to be uploaded. If the folder(s) didn't exist before, a new folder(s) is created. The folder name can contain: - Alphanumeric Characters:</span> <span data-offset-key="11855:3">`a-z`</span> <span data-offset-key="11855:4">,</span> <span data-offset-key="11855:5">`A-Z`</span> <span data-offset-key="11855:6">,</span> <span data-offset-key="11855:7">`0-9`</span> <span data-offset-key="11855:8">- Special Characters:</span> <span data-offset-key="11855:9">`/``_`</span> <span data-offset-key="11855:10">and</span> <span data-offset-key="11855:11">`-`</span> <span data-offset-key="11855:12">- Using multiple</span> <span data-offset-key="11855:13">`/`</span> <span data-offset-key="11855:14">creates a nested folder.</span> <span data-offset-key="11855:15">**Default value**</span> <span data-offset-key="11855:16">- /</span></span></span>
351-
352-
</td>
353-
354-
</tr>
355-
356-
<tr class="tableRow-41a0302b" data-key="11947">
357-
358-
<td data-table="cell" class="tableCell-150ac604" data-key="11917" style="text-align: left;">
359-
360-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="ed9720d221654292aa58142f879dea91"><span data-offset-key="ed9720d221654292aa58142f879dea91:0">**is_private_file**</span> <span data-offset-key="ed9720d221654292aa58142f879dea91:1">optional</span></span></span>
361-
362-
</td>
363-
364-
<td data-table="cell" class="tableCell-150ac604" data-key="11946" style="text-align: left;">
365-
366-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="11918"><span data-offset-key="11918:0">Whether to mark the file as private or not. This is only relevant for image type files. - Accepts</span> <span data-offset-key="11918:1">`true`</span> <span data-offset-key="11918:2">or</span> <span data-offset-key="11918:3">`false`</span><span data-offset-key="11918:4">. - If set</span> <span data-offset-key="11918:5">`true`</span><span data-offset-key="11918:6">, the file is marked as private which restricts access to the original image URL and unnamed image transformations without signed URLs. Without the signed URL, only named transformations work on private images</span> <span data-offset-key="11918:7">**Default value**</span> <span data-offset-key="11918:8">-</span> <span data-offset-key="11918:9">`false`</span></span></span>
367-
368-
</td>
369-
370-
</tr>
371-
372-
<tr class="tableRow-41a0302b" data-key="11988">
373-
374-
<td data-table="cell" class="tableCell-150ac604" data-key="11964" style="text-align: left;">
375-
376-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="a7aff28dce734653b30bdcc49230ad13"><span data-offset-key="a7aff28dce734653b30bdcc49230ad13:0">**custom_coordinates** </span><span data-offset-key="a7aff28dce734653b30bdcc49230ad13:1">optional</span></span></span>
377-
378-
</td>
379-
380-
<td data-table="cell" class="tableCell-150ac604" data-key="11987" style="text-align: left;">
381-
382-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="11965"><span data-offset-key="11965:0">Define an important area in the image. This is only relevant for image type files.</span></span></span>
383-
384-
* <div data-key="c53fb2f1b56b418b9d6b9fb4a06f7792" class="reset-3c756112--listItemContent-756c9114">
385-
386-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="1362a1a179384b28ba7e977050546dab"><span data-offset-key="1362a1a179384b28ba7e977050546dab:0">To be passed as a string with the x and y coordinates of the top-left corner, and width and height of the area of interest in format</span> <span data-offset-key="1362a1a179384b28ba7e977050546dab:1">`x,y,width,height`</span><span data-offset-key="1362a1a179384b28ba7e977050546dab:2">. For example -</span> <span data-offset-key="1362a1a179384b28ba7e977050546dab:3">`10,10,100,100`</span></span></span>
387-
388-
</div>
389-
390-
* <div data-key="844aad56bbb048179413ba0ca4fa120e" class="reset-3c756112--listItemContent-756c9114">
391-
392-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="2a3ff3400c6142118f3d9c3bd8bce8b5"><span data-offset-key="2a3ff3400c6142118f3d9c3bd8bce8b5:0">Can be used with</span> <span data-offset-key="2a3ff3400c6142118f3d9c3bd8bce8b5:1">`fo-custom`</span><span data-offset-key="2a3ff3400c6142118f3d9c3bd8bce8b5:2">transformation.</span></span></span>
393-
394-
</div>
395-
396-
* <div data-key="6bd6a4128df149ccbf8ed85c23cb296a" class="reset-3c756112--listItemContent-756c9114">
397-
398-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="f6e308adfee44156ad8ed6b849a7e65e"><span data-offset-key="f6e308adfee44156ad8ed6b849a7e65e:0">If this field is not specified and the file is overwritten, then customCoordinates will be removed.</span></span></span>
399-
400-
</div>
401-
402-
</td>
403-
404-
</tr>
405-
406-
<tr class="tableRow-41a0302b" data-key="12023">
407-
408-
<td data-table="cell" class="tableCell-150ac604" data-key="12002" style="text-align: left;">
409-
410-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="455adcd180e141d2b1cc799f29b5b846"><span data-offset-key="455adcd180e141d2b1cc799f29b5b846:0">**response_fields**</span> <span data-offset-key="455adcd180e141d2b1cc799f29b5b846:1">optional</span></span></span>
411-
412-
</td>
413-
414-
<td data-table="cell" class="tableCell-150ac604" data-key="12022" style="text-align: left;">
415-
416-
<span class="text-4505230f--TextH400-3033861f--textContentFamily-49a318e1"><span data-key="12003"><span data-offset-key="12003:0">Comma-separated values of the fields that you want ImageKit.io to return in response. For example, set the value of this field to</span> <span data-offset-key="12003:1">`tags,custom_coordinates,is_privateFile,metadata`</span> <span data-offset-key="12003:2">to get value of</span> <span data-offset-key="12003:3">`tags`</span><span data-offset-key="12003:4">,</span> <span data-offset-key="12003:5">`custom_coordinates`</span><span data-offset-key="12003:6">,</span> <span data-offset-key="12003:7">`is_privateFile`</span> <span data-offset-key="12003:8">, and</span> <span data-offset-key="12003:9">`metadata`</span> <span data-offset-key="12003:10">in the response.</span></span></span>
417-
418-
</td>
419-
420-
</tr>
421-
422-
</tbody>
423-
424-
</table>
425-
if upload is succeeded, `error` will be `None` and the result will be same as what is received from ImageKit's
426-
servers. If the upload fails, `error` will be the same as what is received from ImageKit's servers and the result will
427-
be `None`
255+
If the upload succeed, `error` will be `null` and the `result` will be the same as what is received from ImageKit's servers.
256+
If the upload fails, `error` will be the same as what is received from ImageKit's servers and the `result` will be null.
428257

429258
## File Management
430259

tests/test_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ class TestPHashDistance(unittest.TestCase):
1414
def test_phash_distance(self):
1515
"""Tests if phash_distance working properly
1616
"""
17-
a, b = ("f06830ca9f1e3e90", "f06830ca9f1e3e90")
18-
c, d = ("2d5ad3936d2e015b", "2d6ed293db36a4fb")
17+
a, b = ("33699c96619cc69e", "968e978414fe04ea")
18+
c, d = ("33699c96619cc69e", "33699c96619cc69e")
1919
e, f = ("a4a65595ac94518b", "7838873e791f8400")
2020

21-
self.assertEqual(imagekit_obj.phash_distance(a, b), 0)
22-
self.assertEqual(imagekit_obj.phash_distance(c, d), 17)
21+
self.assertEqual(imagekit_obj.phash_distance(a, b), 30)
22+
self.assertEqual(imagekit_obj.phash_distance(c, d), 0)
2323
self.assertEqual(imagekit_obj.phash_distance(e, f), 37)
2424
self.assertRaises(TypeError, imagekit_obj.phash_distance, "", "dkf90")
2525
self.assertRaises(TypeError, imagekit_obj.phash_distance, 1234, 111)

0 commit comments

Comments
 (0)