Can't upload a file through the api

Hi! I’m having problems using the upload api endpoint(https://docs.gitlab.com/ce/api/projects.html#upload-a-file). I constantly receive {"error":"file is invalid"}. I’m trying format a POST request in the chrome extension Advanced Rest Client to figure out how this should work, but all I can receive back is the error. My request looks like:

  • url: http://[private-gitlab]/api/v4/projects/[Project ID]/uploads
  • headers:
  • PRIVATE-TOKEN: [access_token]
  • Content-Type: application/json
  • Raw payload: {“file”: “/Users/usr/projects/go/src/hello/hello.go”}

I’ve tried it with various text files and images, with the goal being to upload .zip files to attach to tag release notes. I get the invalid message almost every time, but sometimes get {"error":"file is missing"}. I have yet to successfully upload a file. Any feedback would be extremely helpful at this point.

note: I should say I can create POST requests to create tags just fine, so I know my urls and tokens are OK, it’s just something to do with the how to do the files.

I feel like something is formatted wrong with my raw payload. But I’m not sure how it’s supposed to be set up properly. Is file not a direct path, does it need the file contents or something?

I found that there is a problem in Advanced Rest Client trying to upload image in project just like you. Than I tried with Insomnia client and it works fine. How do you pass you image string value in the json in your code? I`m trying to solve this for a couple of days.

Hey, sorry it took me so long to respond. I still haven’t solved this and kind of moved on. I’ll try doing it with Postman and see if that client handles it better. My scripts were written in ruby, I’ll see if I can dig up an example later.

Any updates? I’ve run into this problem as well.

Hi, I’m having the same issue trying to commit a zip file though the API - is there any updates on this? Thanks

Has this problem been solved?I made the same mistake

Today 2021 I’m having the same issue trying to post with multipart/form
$issueResponse = $httpClient->post(‘https://gitlab.com/api/v4/projects/17928913/uploads’, [

                'multipart/form-data' => [
                    [
                        'name'     => 'file',
                          //'contents' => file_get_contents(public_path('logo.png')),
                        //'contents' => public_path().'/logo.png'
                        //'contents' => file_get_contents(public_path().'/logo.png'),
                        //'contents' => '@'.public_path('logo.png')
                        'contents' => file_get_contents(public_path('logo.png')),
                    ],
                    [
                        'name'     => 'id',
                        'contents' => 17928913,
                    ]
                ],
                'headers' => [
                    'PRIVATE-TOKEN' => 'myaccesstoken'
                ]
            ]);