0

When the user upload the photo, we don't have it available right after the upload, taking a very little time. The problem is, when the user upload the photo, the Lightning component receive the instruction that the upload is done and tries to get the photo by the URL using the new ID but the photo is not available

What could cause this problem?

@AuraEnabled
public static ConnectApi.Photo UpdatePhoto(Id documentId, String filename) {
    Id userId = UserInfo.getUserId();
    String communityId = ConnectApi.Communities.getCommunities(ConnectApi.CommunityStatus.Live).communities.get(0).id;
    //setPhoto
    ContentVersion content = [SELECT 
                              ContentModifiedById, 
                              ContentDocumentId, 
                              FileExtension, 
                              FileType, 
                              ContentSize, 
                              ContentUrl, 
                              Id, 
                              VersionData,
                              VersionNumber 
                              FROM 
                              ContentVersion 
                              WHERE 
                              ContentDocumentId=: documentId];

    ConnectApi.BinaryInput bi = new ConnectApi.BinaryInput(content.VersionData, 'image/' + content.FileType.toLowerCase(), filename);

    ConnectApi.Photo photo = ConnectApi.UserProfiles.setPhoto(communityId, userId, bi);

    ContentDocument cd = [SELECT id
                        FROM ContentDocument
                        WHERE Id=:documentId];


    return ConnectApi.UserProfiles.getPhoto(communityId, userId);
}

Your Answer

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

Browse other questions tagged or ask your own question.