Search code examples
office365office365-apps

Office 365 GetByteArrayAsync


I'm stuck with diZerega's image file handler example.

A similar example was also uploaded by Dorrene Brown on GitHub

1.-The solution is provided for a multi tenant environment but no documentation highlights if you must set the multi tenant environment on true in the azure configuration portal, is it a must configuration step or an optional?

2.-I don't understand which specific kind of token I must get to execute the function httpClient.GetByteArrayAsync and have the image as byte-array from SharePoint online, is this bound to the access token which you only get when you do the overload with AcquireTokenByRefreshTokenAsync(refreshToken, clientCredential, resource) or does the overload with only refreshToken and clientCredentials suffice?

3.- At the moment I receive an access token with the overload of refreshToken and clientCredentials and when I try to get the image I keep getting the 401 error not authorized.

 var imgBytes = await httpClient.GetByteArrayAsync("https://MyDev.sharepoint.com/_vti_bin/wopi.ashx/files/9f8ea500aea44c56837ba5bb5b3287a1/contents?access_token=123..");

2,3 Solved- As I was reading this post I got another time the access token but this time with AcquireTokenByRefreshTokenAsync(result.RefreshToken, clientCredential, resource); and the 401 error vanished. Still point number 1 is still unclear.


Solution

  • The solution is provided for a multi tenant environment but no documentation highlights if you must set the multi tenant environment on true in the azure configuration portal, is it a must configuration step or an optional?

    For the multi-tenant app, it is a must configuration to set the multi-tenant to true.

    enter image description here