Skip to content

Project API add avatar #284

@jflefebvre06

Description

@jflefebvre06

Hello,

Could you please add a method to add avatar to projet. Below a sample can help you

public Project addProjectAvatar(final Project project, final File fileToUpload) throws GitLabApiException {
        Validate.notNull(project, "project cannot be null");
        Validate.notNull(fileToUpload, "fileToUpload cannot be null");
        Validate.isTrue(fileToUpload.isFile(), "fileToUpload is not a file");
        try {
            final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
            builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
            builder.addBinaryBody("avatar", fileToUpload, ContentType.DEFAULT_BINARY, fileToUpload.getName());
            // Si on ne passe que l'avatar on obtien une erreur
            builder.addTextBody("name", project.getName(), ContentType.DEFAULT_BINARY);
            final HttpPut put = new HttpPut(this.gitLabApi.getGitLabServerUrl() + this.gitLabApi.getApiVersion().getApiNamespace() + "/projects/" + project.getId());
            put.setHeader("PRIVATE-TOKEN", this.gitLabApi.getAuthToken());
            put.setEntity(builder.build());
            // FIXME Gestion du proxy
            final HttpClient client = HttpClientBuilder.create().build();
            final HttpResponse response = client.execute(put);
            final int statusCode = response.getStatusLine().getStatusCode();
            final HttpEntity responseEntity = response.getEntity();
            ...
        } catch (final IOException ioException) {
            throw new GitLabApiException(ioException);
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions