Код: Выделить всё
public async Task UploadFileAsync(string siteId, string driveId, string folderId, string fileName, byte[] fileContent, string accessToken)
{
HttpClient _httpClient = new HttpClient();
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
try
{
var requestUrl = $"https://graph.microsoft.com/v1.0/sites/{siteId}/drives/{driveId}/items/{folderId}:/{fileName}:/content";
using (var content = new ByteArrayContent(fileContent))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
var response = await _httpClient.PutAsync(requestUrl, content);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("File uploaded successfully.");
}
else
{
Console.WriteLine($"Failed to upload file. Status: {response.StatusCode}, Error: {await response.Content.ReadAsStringAsync()}");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Exception: {ex.Message}");
}
}
Код: Выделить всё
var response = await _httpClient.PutAsync(requestUrl, content);
[img]https:/ /i.sstatic.net/7oGN5FKe.png[/img]
Кто-нибудь может мне помочь в этом?
Подробнее здесь: https://stackoverflow.com/questions/791 ... any-errors