Search code examples
javagitlabgitlab-api

How Fetch file From GitLab using by GitLab4j


How to fetch file from gitLab, using by GitLab4j my code look:

`

    Object obj = 19851511;
    GitLabApi gitLabApi = new GitLabApi("https://gitlab.com/", "TOKEN");

    RepositoryFile file = gitLabApi.getRepositoryFileApi().getFile(obj
            , "https://gitlab.com/kashirin.kostiantyn/fackinproj/-/blob/5cfd2c42ece5532aa174ec8b90700a656651ff92/test.rtf"
            , "master");

` Link in browser is work! After, I have error: Exception in thread "main" org.gitlab4j.api.GitLabApiException: 404 File Not Found

or: Exception in thread "main" org.gitlab4j.api.GitLabApiException: 404 Commit Not Found


Solution

  • if you interest answer in my question, so is

    `

    Object obj = 19851511;
    
    GitLabApi gitLabApi = new GitLabApi("https://gitlab.com/", "TOKEN");
    RepositoryFile file = gitLabApi.getRepositoryFileApi().getFile(obj,"src/.gitkeep" , "master");
    
        System.out.println("TExt decodet \n"+file.getDecodedContentAsString());
        System.out.println("This all info from FILE \n"+file);
    

    ` enjoy

    Thank me!)

    and one more thing! If you get "SSLHandhakeExeption", so use

    gitLabApi.setIgnoreCertificateErrors(true);

    First declare gitlabApi, after gitLabApi.setIgnoreCertificateErrors(true); ,and after all, RepositoryFile