# Retrieve task image or subtask image via api

**URL:** https://kanboard.discourse.group/t/retrieve-task-image-or-subtask-image-via-api/2371
**Category:** Questions
**Created:** [September 17, 2022, 11:56am UTC](https://kanboard.discourse.group/t/retrieve-task-image-or-subtask-image-via-api/2371 "2022-09-17T11:56:27Z")
**Posts on this page:** 12
**Page:** 2

<div class="post-metadata">

### Author: ![alfredb](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/alfredb/32/1051_2.png) [@alfredb](https://kanboard.discourse.group/u/alfredb)
#### Post date: [September 23, 2022, 7:02am UTC](https://kanboard.discourse.group/t/retrieve-task-image-or-subtask-image-via-api/2371/21 "2022-09-23T07:02:35Z")

</div>

Python is not my thing at all, but hasn’t it a curl library?

---

<div class="post-metadata">

### Author: ![dng](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/dng/32/1179_2.png) [@dng](https://kanboard.discourse.group/u/dng)
#### Post date: [September 23, 2022, 7:29am UTC](https://kanboard.discourse.group/t/retrieve-task-image-or-subtask-image-via-api/2371/22 "2022-09-23T07:29:17Z")

</div>

hmmm yeah good call!

I got it working in python via the json api, basically just put this in a for loop iterating over the tasks:

```auto
file_id = image['id']
print ('File ID =>',file_id)
file_encoded = ob.downloadTaskFile(file_id=file_id)
file_decoded = base64.urlsafe_b64decode(file_encoded)
file_dir = 'temp/thumb_test/'
file_name = task_title + '_' + str(file_id) + '.png'
print ('File Name =>',file_name)
try:
    with open(file_dir+file_name, mode='wb+') as f:
        f.write(file_decoded)
        f.close()
except:
        print(traceback.format_exc())

```

---

<div class="post-metadata">

### Author: ![alfredb](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/alfredb/32/1051_2.png) [@alfredb](https://kanboard.discourse.group/u/alfredb)
#### Post date: [September 23, 2022, 9:55am UTC](https://kanboard.discourse.group/t/retrieve-task-image-or-subtask-image-via-api/2371/23 "2022-09-23T09:55:37Z")

</div>

Maybe I dare ask a question:

- What happens when you encounter a task file that isn’t a PNG file?
- Do you check this somewhere?

---

<div class="post-metadata">

### Author: ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)
#### Post date: [September 23, 2022, 10:27am UTC](https://kanboard.discourse.group/t/retrieve-task-image-or-subtask-image-via-api/2371/24 "2022-09-23T10:27:18Z")

</div>

i did this a long time ago using api with vb, but i dont know didly squat about python. i might be able to find that code and figure out what i did, but it was a full desktop interface for KB.

the api does give you info about the file, “is\_image” boolean, and the filename.

---

<div class="post-metadata">

### Author: ![dng](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/dng/32/1179_2.png) [@dng](https://kanboard.discourse.group/u/dng)
#### Post date: [September 23, 2022, 12:46pm UTC](https://kanboard.discourse.group/t/retrieve-task-image-or-subtask-image-via-api/2371/25 "2022-09-23T12:46:16Z")

</div>

> [@alfredb](#):
>
> Maybe I dare ask a question:
> 
> - What happens when you encounter a task file that isn’t a PNG file?
> - Do you check this somewhere?

- yes! thought of that for later;

atm ‘.png’ is derived from the ‘name’ key and ‘is\_image’ is there for a check also as I have a lot of .mp4s as attachments as well.

---

<div class="post-metadata">

### Author: ![dng](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/dng/32/1179_2.png) [@dng](https://kanboard.discourse.group/u/dng)
#### Post date: [September 23, 2022, 12:49pm UTC](https://kanboard.discourse.group/t/retrieve-task-image-or-subtask-image-via-api/2371/26 "2022-09-23T12:49:11Z")

</div>

> [@creecros](#):
>
> i did this a long time ago using api with vb, but i dont know didly squat about python. i might be able to find that code and figure out what i did, but it was a full desktop interface for KB.
> 
> the api does give you info about the file, “is\_image” boolean, and the filename.

Yes, I’m basically making a PySide2 interface probably quite similar to what you’ve made with vb.  
atm it is working, so: yay!!! however a bit slow, booo haha

---

<div class="post-metadata">

### Author: ![dng](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/dng/32/1179_2.png) [@dng](https://kanboard.discourse.group/u/dng)
#### Post date: [September 24, 2022, 3:33pm UTC](https://kanboard.discourse.group/t/retrieve-task-image-or-subtask-image-via-api/2371/27 "2022-09-24T15:33:05Z")

</div>

So everything is working now quite nicely, however I have 1 issue with getting attachments via the json api:

What is the fastest way to get a task attachment? It feels like the api is missing something…

currently I am grabbing them via:

```auto
    getAllTaskFiles(task_id=task_id)

```

then doing this:

```auto
    downloadTaskFile(file_id=file_id)

```

but this is quite slow to process, I’m wondering if there is a way to just download the file by **task\_id** instead of querying the task first to get the **file\_id**? or something like that.

---

<div class="post-metadata">

### Author: ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)
#### Post date: [September 25, 2022, 12:05pm UTC](https://kanboard.discourse.group/t/retrieve-task-image-or-subtask-image-via-api/2371/28 "2022-09-25T12:05:14Z")

</div>

file or files? you would have to know the file\_id for singular.

if you think there is a faster way, you could, i guess combine the plural into one api action. not sure that would make it faster, possibly. worth a shot.

---

<div class="post-metadata">

### Author: ![dng](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/dng/32/1179_2.png) [@dng](https://kanboard.discourse.group/u/dng)
#### Post date: [September 25, 2022, 12:56pm UTC](https://kanboard.discourse.group/t/retrieve-task-image-or-subtask-image-via-api/2371/29 "2022-09-25T12:56:42Z")

</div>

yeah files. ☹

so going through the project and collecting cover images per task card (without knowing the file ids)

---

<div class="post-metadata">

### Author: ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)
#### Post date: [September 25, 2022, 4:35pm UTC](https://kanboard.discourse.group/t/retrieve-task-image-or-subtask-image-via-api/2371/30 "2022-09-25T16:35:04Z")

</div>

ya, like i said, you could create your own api action that does it in one action, but it still would need to iterate through the task to get the file ids, so not sure it would improve the speed, vs 2 api actions. might though.

---

<div class="post-metadata">

### Author: ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)
#### Post date: [September 25, 2022, 4:45pm UTC](https://kanboard.discourse.group/t/retrieve-task-image-or-subtask-image-via-api/2371/31 "2022-09-25T16:45:14Z")

</div>

wait, you said cover images, so are you using the cover images plugin? if so, you know the file id, its stored in metadata. no need to iterate.

---

<div class="post-metadata">

### Author: ![dng](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/dng/32/1179_2.png) [@dng](https://kanboard.discourse.group/u/dng)
#### Post date: [September 26, 2022, 12:02am UTC](https://kanboard.discourse.group/t/retrieve-task-image-or-subtask-image-via-api/2371/32 "2022-09-26T00:02:44Z")

</div>

yes using ‘cover images’ plugin. ah right so can just grab file ID through the metadata via the API. nice

[Previous page](https://kanboard.discourse.group/t/retrieve-task-image-or-subtask-image-via-api/2371.md?page=1)
