Hi
i was trying to upload attachment jpg image file.I can upload image using folowing python command
image = “Desktop/test.jpg”
with open(image,“rb”) as f:
data = f.read()
client.attachments.create_attachment_for_task(task_gid, file_content=data, file_name=“test”,file_content_type=“image”)
It uploads but does not show the image just like when i upload manually.
how to upload image through python api and make it to be seen in task bar.
Hi,
There is another thread about exactly the same thing, you should be able to find it using the search.
Thanks
i think i found your post about it where you’ve posted might be node js code?? but as a beginner python user i still can not find the solution of this. I am googling and trying diferent ways but im still failed to solve this.
Yes I posted my code in node, I can’t really help in Python…
1 Like
Hoping you found the answer by now.
For anyone else running into this problem, attach a file extension to the filename and set the correct content type.
example from the original post:
client.attachments.create_attachment_for_task(task_gid, file_content=data, file_name=“test.jpg”, file_content_type=“image/jpeg”)
2 Likes
yes I got the solution few months before but forgot to share it. solution is just like your example.
it looks like this. I will leave it here if anyone want reference.
client = asana.Client.basic_auth(‘…’)
workspaceID = ‘…’
teamID = “…”
project_gid = “…”
taskList = client.tasks.get_tasks_for_project(project_gid,opt_pretty=True)
taskList = list(taskList)
thumbnailPath = r"thumnail path"
#thumbnailPath where thumnail jpg files exist and filename taken from task name with image file extension
for task in taskList:
infoList =list(task.values())
task_gid=infoList[0]
task_name=infoList[1]
for file in os.listdir(thumbnailPath):
fileName = file.split(“.jpg”)[0]
if task_name == fileName:
imageData = os.path.join(thumbnailPath,file)
with open(imageData,“rb”) as f:
data = f.read()
client.attachments.create_attachment_for_task(task_gid, file_content=data, file_name=“%s.jpg”%fileName,file_content_type=“image/jpeg”)
2 Likes