Need help to get an LFS file using the api

I am trying to use the git api to get a file from my repo without success. Can you give me some pointers? Is an lsfconfig, which I do not have, needed?

When I run my below C# code, I get this response

“message”: “Access forbidden. Check your access level.”,
“documentation_url”: “

I am positive that I am passing my correct credentials.

C# code follows:

        HttpClient client = new HttpClient();
        client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/vnd.git-lfs+json"));
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                    string.Format("{0}:{1}", <my_username>, <my_password>))));

        string json = @"{
                          'operation': 'download',
                          'transfers': [ 'basic' ],
                          'ref': { 'name': 'refs/heads/master' },
                          'objects': [
                              'oid': '9669a62bbe8d8150c11d814509078b5db8f73c97ecfc94beb1dc6b22130adf7b',
                              'size': 4465559,
                              'authenticated': true

        var response = client.PostAsync("<my_repo>/info/lfs/objects/batch", new StringContent(JsonConvert.SerializeObject(json), Encoding.UTF8, "application/json"));

Hi all,

4 days and no replies yet. I wonder if Q&A category is monitored/followed, or simply not a lot are doing LFS using the GitLab api. Thanks.

Hi @litosdesk,

I never tried this operation, but I have a few questions:

  1. Why do you need to download LFS files using API? Why not use git checkout, which seamlessly brings LFS files to your working tree. You even don’t have to know whether a file belongs to LFS or not (

  2. Your code is based on Git LFS Batch API ( rather than GitLab API. Maybe GitLab blocks the former?

Hi alexk,

I am aware of git checkout but what I am trying to do is create a C# application for non-git users so they can just click a button and download all files from a specified version onto a specified local folder on their local computer.

Not sure what is blocking which. After more search, it appears that this has been logged as an issue (

Can’t you do it by running git checkout from within your application?

No impression that they are going to solve it in the near future…