Is it possible to batch upload user profile images in Confluence?

I'm aware of the restrictions and improvement request for allowing administrator's to change a user profile's picture (hey, Atlassian, fix that already!). In the meantime, is there some way to do this in the back-end? Perhaps through the command line interface or a plugin?

3 answers

1 accepted

2 votes
Answer accepted
Davin Studer Community Champion Sep 13, 2013

Works on my machine

Small disclaimer: this works great on my setup. I have not tested it outside of my setup. It should work just fine as I am using the standard API's that come with Confluence, but it is an open source project and I'm not getting paid for it, so I haven't done extensive testing in all scenarios.

That said, here is a utility I created to upload user photos in batch. You can get the source here ...

The compiled binary is here...

Basically you supply the program with a folder where the user photos are. It will pull in all the .jpg,.jpeg, .tif, .tiff, .png, and .bmp files in the folder. The photos should be in this format username.png, username.jpg, etc. Since Confluence profile photos are 48x48 and most photos are not square it will do face detection and then crop the photo unless you specify otherwise(via a checkbox). It has a form mode (just click on the executable) and a headless mode (supply the command line arg /headless) for automating the process. Hope this helps you out.

Hi Davin,

This looks really cool and how good of you to go out of your way to produce such a fine looking program for free. I'll give you the kudos now (before using it) as I need to do some things first.



OK, unfortunately I couldn't get it to work. I supplied with the correct information, photos, etc. But I get the following error:

"System.InvalidOperationException: Client found response content type of 'text/html; charset=UTF-8', but expected 'text/xml'.

The rest of error message I can't get to because of the odd way the error message is returned. Any ideas?


Davin Studer Community Champion Sep 16, 2013

Hmmm ... shoot. :) Would you be able to let me see what is in the ConfluenceProfilePhotos.exe.config file ... minus the encrypted password line? Also, do you have Confluence behind a reverse proxy or are you accessing the Tomcast server directly? Lastly, what OS is the server? Oh also, do you have the "Remote API" feature turned on under Confluence Admin -> General Configuration? If you want an address to email the config file you could send it to fredclown at gmail.

Thanks, Davin. I've sent you an email.

Davin Studer Community Champion Sep 19, 2013

Looks like the issue had to do with the SOAP API plugin. Once that was fixed the upload utility worked.

OK I have used Davin's program and I can report that it is exactly what I wanted. Once the issues with the SOAP interface was resolved it worked like a charm. It uploaded them quickly and efficiently and I didn't notice any significant performance problems during the process.

Excellent program!

Davin Studer Community Champion Feb 23, 2015

Just released v1.1.0.0. It does better face detection and cropping, has a version checker, and a test harness to see how the system will crop and resize your photos.

#Script to read *.png files from a directory and upload as profile picture for users

import os
import shutil
import fnmatch
import xmlrpclib
import string
import re

#Function to generate files that match a given filename pattern with in a directory
def get_files_in_directory(filepat,top):
    for path, dirlist, filelist in os.walk(top):
        for userphoto in fnmatch.filter(filelist,filepat):            
            yield os.path.join(path,userphoto)

#Main Function
if __name__ == '__main__':
    #Source Directory must be specified
    source = 'C:\BulkPhotoUpload\UserPhotos' # From where pictures of the users are read
    #Destination Directory must be specified
    destination = 'C:\BulkPhotoUpload\Archive' # To where pictures of the users are archived after uploading
    #The confluence server must be specified and the XML-RPC API must be enabled in the system
    server = xmlrpclib.ServerProxy('http://localhost:8090/rpc/xmlrpc')
    #Must specify the UserName & the Password of the usercontext on which the operation must be performed
    token = server.confluence1.login('username', 'password');
    #Gets all the PNG files from the directory
    userphotocollection = get_files_in_directory("*png",source)
    #Iterate the files to upload them as profile photo for users
    for userPhoto in userphotocollection:        
        pictureData = xmlrpclib.Binary(open(userPhoto,'rb').read())
        picName = os.path.basename(userPhoto)         
        userName = os.path.splitext(picName)[0]        
        profilePictureAdded = server.confluence1.addProfilePicture(token, userName, picName, 'image/png', pictureData)
    if profilePictureAdded:
        #Move the uploaded images to the Archive directory        
        print "Successfully added profile picture for %s" % userName
        shutil.move(userPhoto, destination)
        print "Failed to add profile picture for %s" % userName        
except xmlrpclib.Fault, err:
    print "Fault code: %d" % err.faultCode
    print "Fault string: %s" % err.faultString

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

1,627 views 4 13
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you