Last active
February 1, 2019 07:20
-
-
Save dimobelov/ee70eb73762dcbdddb72cca307e6280c to your computer and use it in GitHub Desktop.
GitLab API - Upload File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I created a function to also import issue attachements. I still need to add it to this lib. For anyone looking to do the work by yourself: | |
See: https://docs.gitlab.com/ee/api/projects.html#upload-a-file | |
private async Task<string> GitLabFileUploadAsync(string url, string token, string projectId, byte[] file, string fileName) | |
{ | |
using (var httpClient = new HttpClient()) | |
{ | |
var form = new MultipartFormDataContent | |
{ | |
{ new ByteArrayContent(file, 0, file.Length), "file", fileName } | |
}; | |
form.Headers.Add("PRIVATE-TOKEN", token); | |
using (HttpResponseMessage response = await httpClient.PostAsync($"{url}/api/v4/projects/{projectId}/uploads", form)) | |
{ | |
response.EnsureSuccessStatusCode(); | |
return response.Content.ReadAsStringAsync().Result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment