Hari Murugesan

Hari Murugesan

  • NA
  • 39
  • 3.3k

sharepoint profile image not displayed

May 31 2018 2:13 AM
Hi Guys i'm new in ionic with sharepoint
 
I have developed a Mobile app using ionic3 with sharepoint.
 
Now i have to get user profile picture in my app.
 
I have tried these are the way can't achieve here is my tried code.
 
First way tried like this
 
abc.sharepoint.com/sites/qa/_layouts/15/userphoto.aspx?size="s"&accountname="[email protected]"
 
Second way tried like this
 
These url iam geting using people picker result. PictureURL property
 
https://abc.sharepoint.com/User Photos/ProfilePictures/abc_onmicrosoft_com_MThumb.jpg", "Muthu.jpeg"
 
These Second method always return
  
401 UNAUTHORIZED
 
Above url using to call this method.
  1. public downloadFile(url: string, fileName: string) {  
  2.   
  3.    let options = this._apiHeaderForImageURL();  
  4.    this._http.get(url, options)  
  5.       .subscribe((data) => {        
  6.          //here converting a blob to base 64 For internal view purpose in image src  
  7.          var reader = new FileReader();  
  8.          reader.readAsDataURL(data.blob());  
  9.          reader.onloadend = function () {  
  10.          console.log("Base64", reader.result);  
  11.       }  
  12.         
  13.       //Here Writing a blob file to storage   
  14.       this.file.writeFile(this.file.externalRootDirectory, fileName, data.blob(), {       replace: true })  
  15.          .then((success) => {  
  16.             console.log("File Writed Successfully", success);  
  17.          }).catch((err) => {  
  18.             console.log("Error While Wrinting File", err);  
  19.          });  
  20.       });  
  21.  }
  22. public _apiHeaderForImageURL() {  
  23.    let headers = new Headers({ 'Content-Type''image/jpeg' });  
  24.    headers.append('Authorization''Bearer ' + localStorage.getItem("token"));  
  25.    let options = new RequestOptions({ headers: headers, responseType: 3 });                                    
  26.    return options;  
  27. }  
The first api call worked fine result also sucess but image not displayed properly. Thats the problem i'm facing. 

The result comes an default image like this only.

  


pls help me to achieve this. Any help warmly accepted.

Iam doing long time stuff to achieve this still i cant achieve pls give some idea.

Is any other way is available to get user picture in ionic 3 using spfx?

Answers (6)