Download File – Sharepoint / MS Graph
Hello good evening,
I’ve been working on a problem for quite a while now and can’t get any further. I hope someone here can help me.
Initial situation:
I have a sharepoint page.
This page contains lists.
These lists contain text columns and also image columns.
The lists receive data from Powerapps.
So far so good. It works.
Now I am working on the implementation of a programme that will run on a server. This programme retrieves the data from the lists regularly.
I use Microsoft Graph to retrieve the lists. That also works. So token, graphclient, communication etc. are all good.
But: For the image column I only get a json back, which contains the server url and also the relative url. If I put the url together and call it up via the browser, I can also see the image.
Well, I thought to myself. Then I download the image directly via Http and save it accordingly, but that doesn’t work! I always get the error 401 – Unauthorised.
I load my Http client with the appropriate header and the token which is also valid.
I had created the app in the Azure Entra and also set the authorisations accordingly. Files.Read.All, Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All, Sites.Selected.
Retrieving the list and processing it with MS Graph also works. It’s just a matter of downloading the image file 😞
I use C#.
AuthenticationResult tokenMSAL = getToken();
using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorisation = new AuthenticationHeaderValue(‘Bearer’, tokenMSAL.AccessToken);
// Download the image and save it
var img = httpClient.GetAsync(signatureUrl).GetAwaiter().GetResult();
As I am at a loss at the moment and have already invested a lot of time, I hope that someone here can give me an alternative solution or knows which authorisation must be set for the download to work.
Thank you very much and have a nice evening!
Greetings Manu
Hello good evening,I’ve been working on a problem for quite a while now and can’t get any further. I hope someone here can help me. Initial situation:I have a sharepoint page.This page contains lists.These lists contain text columns and also image columns.The lists receive data from Powerapps.So far so good. It works. Now I am working on the implementation of a programme that will run on a server. This programme retrieves the data from the lists regularly.I use Microsoft Graph to retrieve the lists. That also works. So token, graphclient, communication etc. are all good.But: For the image column I only get a json back, which contains the server url and also the relative url. If I put the url together and call it up via the browser, I can also see the image.Well, I thought to myself. Then I download the image directly via Http and save it accordingly, but that doesn’t work! I always get the error 401 – Unauthorised.I load my Http client with the appropriate header and the token which is also valid.I had created the app in the Azure Entra and also set the authorisations accordingly. Files.Read.All, Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All, Sites.Selected.Retrieving the list and processing it with MS Graph also works. It’s just a matter of downloading the image file 😞 I use C#. AuthenticationResult tokenMSAL = getToken();using (HttpClient httpClient = new HttpClient()){httpClient.DefaultRequestHeaders.Authorisation = new AuthenticationHeaderValue(‘Bearer’, tokenMSAL.AccessToken);// Download the image and save itvar img = httpClient.GetAsync(signatureUrl).GetAwaiter().GetResult(); As I am at a loss at the moment and have already invested a lot of time, I hope that someone here can give me an alternative solution or knows which authorisation must be set for the download to work. Thank you very much and have a nice evening!Greetings Manu Read More