public async static Task <ImageCreationInformation> UpdateImageInformationAsync(string caption, List <string> tags, string fileId, string accessToken) { ImageCreationInformation imageInformation = null; var updates = new { description = caption }; var client = new HttpClient(); try { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); var uri = new Uri($"https://graph.microsoft.com/v1.0/me/drive/items/{fileId}"); var request = new HttpRequestMessage(new HttpMethod("PATCH"), uri) { Content = new StringContent(JsonConvert.SerializeObject(updates), System.Text.Encoding.UTF8, "application/json") }; var response = await client.SendAsync(request); var stream = await response.Content.ReadAsStringAsync(); imageInformation = JsonConvert.DeserializeObject <ImageCreationInformation>(stream); } catch (Exception ex) { } return(imageInformation); }
public async static Task <ImageCreationInformation> UploadImageToAppFolderAsync(string folderId, string fileName, byte[] bytes, string accessToken) { ImageCreationInformation imageInformation = null; var content = new ByteArrayContent(bytes); var client = new HttpClient(); try { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); var uri = new Uri("https://graph.microsoft.com/v1.0/me/" + string.Format("/drive/items/{0}:/{1}:/content", folderId, fileName)); var response = await client.PutAsync(uri, content); var stream = await response.Content.ReadAsStringAsync(); imageInformation = JsonConvert.DeserializeObject <ImageCreationInformation>(stream); } catch (Exception ex) { } return(imageInformation); }
public async static Task <ImageCreationInformation> GetImageDetailsAsync(string fileId, string accessToken) { ImageCreationInformation imageInformation = null; var client = new HttpClient(); try { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); var uri = new Uri($"https://graph.microsoft.com/v1.0/me/drive/items/{fileId}"); var response = await client.GetAsync(uri); var stream = await response.Content.ReadAsStringAsync(); imageInformation = JsonConvert.DeserializeObject <ImageCreationInformation>(stream); } catch (Exception ex) { } return(imageInformation); }