3

I'm just wondering the type of value that this method (SP.UserProfiles.PeopleManager.setMyProfilePicture) receives as a parameter 'cause I've tried already with different values and still not able to put my 'golden fish' as my own profile picture... And also of course provide the posibility to others to change their own profile picture through Javascript model.

I need to clarify there's no way that I can try a CSOM option since I don't have handy that alternative (due to internal policies). My SP version is 2013.

2

You can try the below javascript functions:

var getFileAsArrayBuffer = function (file) {
    var dfd = $.Deferred();
    var fr = new FileReader();
    fr.onload = function (e) {
        dfd.resolve(e.target.result);
    }
    fr.onerror = function (e) {
        dfd.reject(e.target.error);
    }
    fr.readAsArrayBuffer(file);
    return dfd.promise();
};

$("#uploadFile").change(function(){ 
getFileAsArrayBuffer($("#uploadfile")[0].files[0]).then(function(arrayBuffer) {
var dfd = $.Deferred();
    $.ajax({
        url:"https://sitecollectionurl/_api/SP.UserProfiles.PeopleManager/SetMyProfilePicture",
        type: "POST",
        data: arrayBuffer,
        processData: false,
        headers: {
            "accept": "application/json;odata=verbose",
            "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value,
            "content-length": arrayBuffer.byteLength
        },
        success: function (data) { 
            console.log('sucessfully updated my profile picture');
            dfd.resolve(data);
        },
        error: function (err) { 
            console.log("something went wrong" + err);
            dfd.reject(err);
        }
        });
    });
});

And your html would be as:

<input type="file" id="uploadFile" />

Modified from - User profiles REST API reference

  • Thanks, I tried that option but everytime I send the request to upload the image I receive an error from the server, also the windows security dialog comes up asking me for my user and password. I reviewed the permissions and from the settings the users have the chance to make updates to their profiles, so apparently this seems to be some sort of restriction either on the domain mysite.sharepoint... or in my site collection. – Vladimir López Jun 15 '17 at 16:23
  • You need to set CrossDomainPhotosEnabled to true, check this link and accordingly run the powershell. wictorwilen.se/… – Gautam Sheth Jun 16 '17 at 14:09
0

I have done some research to help you out with your request and I found the following:

  • Changing the user profile photo is doable using JSOM using (POST) http://<siteUri>/_api/SP.UserProfiles.PeopleManager/SetMyProfilePicture and pass the picture parameter in the request body

There is an example here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.