locked
How do I upload an image from my gallery to a sharepoint library ? RRS feed

  • Question

  • User335627 posted

    I want my application to fetch the image from gallery and upload the same image to the Sharepoint library.

    I googled for a solution but unable to find one that I could understand. Anyone who has implemented the same or has a sample with them. Do reply

    Monday, October 30, 2017 7:52 AM

All replies

  • User82335 posted

    @sameerpurohit said: I want my application to fetch the image from gallery and upload the same image to the Sharepoint library.

    I googled for a solution but unable to find one that I could understand. Anyone who has implemented the same or has a sample with them. Do reply

    looking solution for the same.

    Monday, October 30, 2017 10:09 AM
  • User363134 posted
    • use AzureActiveDirectoryAuthenticator and get the accessToken

    • get images from gallery using MessagingCenter.Subscribe for pick image from gallery

    • upload Images C# using (var client = new HttpClient()) { var SourceContent=ImagebyteArrayContent; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", acessToken); using (var response = client.PostAsync(new Uri("your tenant.sharepoin.com" + "/_api/web/GetFolderByServerRelativeUrl('/PublishingImages')/Files/add(url='" + filename + "',overwrite=true)"), new StreamContent(new MemoryStream(SourceContent))).Result) { if (response.IsSuccessStatusCode) { success = true; } } }
    Thursday, December 14, 2017 12:08 PM
  • User363134 posted

    @AjaysinhDodiya said: * use AzureActiveDirectoryAuthenticator and get the accessToken

    • get images from gallery using MessagingCenter.Subscribe for pick image from gallery
    • upload Images C# using (var client = new HttpClient()) { var SourceContent=ImagebyteArrayContent; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", acessToken); using (var response = client.PostAsync(new Uri("your tenant.sharepoin.com" + "/_api/web/GetFolderByServerRelativeUrl('/PublishingImages')/Files/add(url='" + filename + "',overwrite=true)"), new StreamContent(new MemoryStream(SourceContent))).Result) { if (response.IsSuccessStatusCode) { success = true; } } }
    Thursday, December 14, 2017 12:09 PM
  • User64943 posted

    @AjaysinhDodiya can you provide more information about how to use AzureActiveDirectoryAuthenticator to get the accessToken?

    Thursday, March 22, 2018 7:51 PM
  • User363134 posted

    Hello @"BrunoPasquini.7813" Try Following Code for get AccessToken

    install Microsoft.IdentityModel.Clients.ActiveDirectory in android and ios and create dependencyService

    pcl

    public interface IAzureActiveDirectoryAuthenticator
    {
        Task<string> Authenticate(string authority, string resource, string clientId, string returnUri);
        Task LogOut(string authority);
    }
    

    for Android

    class DroidAzureADAL : IAzureActiveDirectoryAuthenticator
    {
        public async Task<string> Authenticate(string authority, string resource, string clientId, string returnUri)
        {
            var authContext = new AuthenticationContext(authority);
            if (authContext.TokenCache.ReadItems().Any())
                authContext = new AuthenticationContext(authContext.TokenCache.ReadItems().First().Authority);
    
            var uri = new Uri(returnUri);
            var platformParams = new PlatformParameters((Activity)Forms.Context);
            var authResult = await authContext.AcquireTokenAsync(resource, clientId, uri, platformParams);
    
            var accessToken = authResult.AccessToken;
            return accessToken;
        }
    
        public Task LogOut(string authority)
        {
            var authContext = new AuthenticationContext(authority);
            authContext.TokenCache.Clear();
            return Task.CompletedTask;
        }
    }
    

    for iOS

     public class IosAzureADAL : IAzureActiveDirectoryAuthenticator
    {
        public async Task<string> Authenticate(string authority, string resource, string clientId, string returnUri)
        {
            var authContext = new AuthenticationContext(authority);
            if (authContext.TokenCache.ReadItems().Any())
                authContext = new AuthenticationContext(authContext.TokenCache.ReadItems().First().Authority);
    
            var controller = UIApplication.SharedApplication.KeyWindow.RootViewController;
            var uri = new Uri(returnUri);
            var platformParams = new PlatformParameters(controller);
            var authResult = await authContext.AcquireTokenAsync(resource, clientId, uri, platformParams);
    
            var accessToken = authResult.AccessToken;
            return accessToken;
        }
    
        public Task LogOut(string authority)
        {
            throw new NotImplementedException();
        }
    }
    
    Friday, March 23, 2018 2:34 PM
  • User243044 posted

    @AjaysinhDodiya Hi , I am using the same it is working fine when I login first time but when I try to refresh the Token it is not working , can you please suggest that how to refresh the Token.

    Monday, January 14, 2019 7:07 AM
  • User355450 posted

    @ajau> @AjaysinhDodiya said:

    Hello @"BrunoPasquini.7813" Try Following Code for get AccessToken

    install Microsoft.IdentityModel.Clients.ActiveDirectory in android and ios and create dependencyService

    pcl

    public interface IAzureActiveDirectoryAuthenticator
    {
        Task<string> Authenticate(string authority, string resource, string clientId, string returnUri);
        Task LogOut(string authority);
    }
    

    for Android

    class DroidAzureADAL : IAzureActiveDirectoryAuthenticator
    {
        public async Task<string> Authenticate(string authority, string resource, string clientId, string returnUri)
        {
            var authContext = new AuthenticationContext(authority);
            if (authContext.TokenCache.ReadItems().Any())
                authContext = new AuthenticationContext(authContext.TokenCache.ReadItems().First().Authority);
    
            var uri = new Uri(returnUri);
            var platformParams = new PlatformParameters((Activity)Forms.Context);
            var authResult = await authContext.AcquireTokenAsync(resource, clientId, uri, platformParams);
    
            var accessToken = authResult.AccessToken;
            return accessToken;
        }
    
        public Task LogOut(string authority)
        {
            var authContext = new AuthenticationContext(authority);
            authContext.TokenCache.Clear();
            return Task.CompletedTask;
        }
    }
    

    for iOS

     public class IosAzureADAL : IAzureActiveDirectoryAuthenticator
    {
        public async Task<string> Authenticate(string authority, string resource, string clientId, string returnUri)
        {
            var authContext = new AuthenticationContext(authority);
            if (authContext.TokenCache.ReadItems().Any())
                authContext = new AuthenticationContext(authContext.TokenCache.ReadItems().First().Authority);
    
            var controller = UIApplication.SharedApplication.KeyWindow.RootViewController;
            var uri = new Uri(returnUri);
            var platformParams = new PlatformParameters(controller);
            var authResult = await authContext.AcquireTokenAsync(resource, clientId, uri, platformParams);
    
            var accessToken = authResult.AccessToken;
            return accessToken;
        }
    
        public Task LogOut(string authority)
        {
            throw new NotImplementedException();
        }
    }
    

    Do you have any idea about MSAL token, because ADAL will be no more used in login.??

    Thursday, March 4, 2021 12:11 PM