-
Notifications
You must be signed in to change notification settings - Fork 485
Closed
Labels
Description
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);
}
}