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

2
  • 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 Commented Sep 19, 2018 at 9:07
  • @KedarnagMukanahallipatna Ok, but how do you upload an avatar? And how do you set avatar_url, via the avatar property? Commented Sep 19, 2018 at 9:20

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.