Upload file via API v4 = 400 bad request
I have a file I wish to update upon some events, so I decided to write a little script that converts my file content to base64 and executes a proper cURL call to gitlab's API v4. Here is the cURL part:
curl --request PUT --header 'PRIVATE-TOKEN: MY-TOKEN-HERE' 'https://gitlab.example.com/api/v4/projects/MY-PROJECT-ID-HERE/repository/files/data%2Ejson?file_path=data%2Ejson&branch=master&commit_message=update%20data%20file&encoding=base64&content=eyJrZXkiOiJ2YWx1ZSJ9'
This snippet works great, until the
content part of the url gets bigger... In fact, after some updates, I started to observe
400 bad request responses from gitlab.com and I could not understand why during like 1 hour. Then I realized my file has now reached 55kb representing 76kb in base64, and this is what causes the error.
I am no http expert put I guess URLs cannot handle 76kb strings...
So my question is 2 fold:
- What shall I do to properly upload my file using the API ?
- Wouldn't it be safer/saner to have files uploaded using some proper body/multipart stuff like we normally do over the web?