Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload an image to use in issue comments via Github API

Tags:

github

ios

api

I'm currently working with Github API to make an iOS github client app. I'd like to implement the feature of creating issues with images. My question is how to upload an image for issue comments via API. We're able to upload the image by drag-and-drop via browser in github.com like image below: image_upload_in_browser

I'd like to use this https://cloud.githubusercontent.com/assets/~~~.PNG. Any way to upload to https://cloud.githubusercontent.com via API or something?

like image 503
Justin Sato Avatar asked Jan 11 '17 01:01

Justin Sato


2 Answers

By the Feb 2020 there are still no official solution to upload files via API to be used in the github issues.

Simple solution is to use a repository branch (you can name it assets). You can link to them from the github issues easily, just use raw link with last commit SHA:

https://github.com/ORG/REPO/raw/LAST_SHA/PATH

This kind of link will be rendered in the issues body always correctly.

like image 194
Dmitry Polushkin Avatar answered Nov 07 '22 01:11

Dmitry Polushkin


Ever I also try to find one way to make it.But there is not any available method to do it. I'm doing some extra test to find that you can observe the drag-and-drop action in your devtool-network panel.

I find that https://github.com/upload/assets/21842410 be requested with PUT method, and its response is {"id":21842410,"name":"-2.png","size":1261,"content_type":"image/png","href":"https://cloud.githubusercontent.com/assets/3518853/21842410/7c3f6812-d79b-11e6-8209-e49b44aaa883.png","original_name":null}

I've not finished my test, if this inspires you and you have time to implement any demo, please tell me your result. :)

like image 34
yupengzhang Avatar answered Nov 07 '22 00:11

yupengzhang