-
Notifications
You must be signed in to change notification settings - Fork 485
Description
I want to update the content of a file in the repository.
I tried the official API command with postman:
PUT /projects/:id/repository/files/:file_path?branch=master
&author_email=author%40example.com
&content=some%20other%20content
&commit_message=update%20file
https://docs.gitlab.com/ee/api/repository_files.html
and that works perfectly.
With this I can just input the new file content as urlencoded string with
content=new%20content
I tried to update the content of a file in the repository with the updateFile method from the RepositoryFileAPI.
For that I retrieved the existing README file content with
repositoryFileApi.getOptionalFile(...).getContent()
but that doesn't give the expected output.
I guess I have to use repositoryFileApi.getRawFile() for that.
But how to set the new content?
I tried with repositoryFile.setContent(newContent) followed by updateFile but the new file content in the repository is not readable. Just looks like random symbols and is way to short. My first thought was that it is a encoding issue but I'm not sure if setting repositoryFile.content even is the right thing to do in the first place since getContent already didn't return the raw document content.
Is there a easy way to just do the above PUT from the official documentation to update the content of a repository file?