1

During a migration from gitswarm to gitlab we lost all of the projects avatar. I'm trying to restore them via a python script, but while it is clear how to set the path of the avatar via the project settings API, I do not understand how to upload the avatar. I searched the GitLab API documentation, but I was not able to find anything. Can someone help me please?

PS: GitLab API: upload projects avatar is of no help, since nobody explained the upload command

ErniBrown
  • 1,283
  • 12
  • 25
  • I don't think there is such a thing, what I do is upload an avatar and then set the `avatar_url`. You can take a look at [this](https://docs.gitlab.com/ce/api/projects.html#edit-project) – Kedarnag Mukanahallipatna Sep 19 '18 at 09:07
  • @KedarnagMukanahallipatna Ok, but how do you upload an avatar? And how do you set avatar_url, via the avatar property? – ErniBrown Sep 19 '18 at 09:20

1 Answers1

3

Finally I was able to upload the avatar of a project via api and python request. There is no need to upload the file first and then set the url, one can simply use the "Edit project" api:

import requests

filename = 'avatar.png'
baseUrl = 'https://gitlabrepositoryaddress.com'
url = baseUrl + '/api/v4/projects/' + str(id)
up = {'avatar':(filename, open(filename, 'rb'), 'multipart/form-data')}
authHeader = {'PRIVATE-TOKEN': 'XXXXXXXXXX'}
request = requests.put(url, files=up, headers=authHeader)

Reference for the api is here: https://docs.gitlab.com/ee/api/projects.html#edit-project

I hope this may help someone else

ErniBrown
  • 1,283
  • 12
  • 25