msgraph
2 Topicsuploading local files from file share to SharePoint Online using MSGraph
Hi There, I am desperately searching for any blog or any article that explains the steps about how to upload local file share documents to SharePoint Online using MSGraph through a c# console application. Thank you so much for your help.. As of now i am using this code below to upload files using a PUT call. the code executes fine without error but when i open the file in SharePoint Online i get error stating "Sorry, this document cant be opened for editing". can anyone help me here please? public async Task CallWebApiAndProcessResultASyncFileUpload(string webApiUrlFileUpload ,string accessTokenFileUpload) { using (HttpClient client = new HttpClient()) { //String requestURI = webApiUrlFileUpload; //HttpContent httpContent = new StringContent("This Message is posted from Visual Studio Lab", Encoding.UTF8, "text/plain"); //HttpRequestMessage newPostRequest = new HttpRequestMessage(HttpMethod.Put, requestURI); //newPostRequest.Content = httpContent; //newPostRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessTokenFileUpload); //var newResponse = await client.SendAsync(newPostRequest); //var theResponseString = await newResponse.Content.ReadAsStringAsync(); String requestURI = webApiUrlFileUpload; var path = @"C:\Users\Name\Desktop\TestDoc.docx"; var multiForm = new MultipartFormDataContent(); FileStream fs = File.OpenRead(path); multiForm.Add(new StreamContent(fs), "file", Path.GetFileName(path)); HttpRequestMessage newPostRequest = new HttpRequestMessage(HttpMethod.Put, requestURI); newPostRequest.Content = multiForm; newPostRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessTokenFileUpload); var newResponse = await client.SendAsync(newPostRequest); var theResponseString = await newResponse.Content.ReadAsStringAsync(); } }1.2KViews0likes1CommentHow to create an <img> tag containing MSGraph photo/$value response BLOB
I'm creating a Sharepoint Application (using Shrepoint Framework) and I'm not being able to retrieve the Pohto BLOB returned when calling MSGraph "/me/photo/$value" api. I don't know how to convert the BLOB into a Base64 string. I know that the responseraw.body is a readable stream, but don't know hot to access it and use as a SRC of a IMG tag. I have made many attempts, I'm writing one to explain what I'm trying to accomplish: this.context.msGraphClientFactory .getClient() .then((client: MSGraphClient): void => { client.api('/me/photo/$value') .get((error, response: any, rawResponse?: any) => { const blobUrl = window.URL.createObjectURL(rawResponse.body); document.getElementById("myPhoto").setAttribute("src", blobUrl); }); }); This code fails because creteObjectURL has been deprecated. The MSGraph call works, but I can't process the response. Any suggestions?1.2KViews0likes1Comment