Hi All,

I am writing a python Script which tries to read png files with title as username for e.g admin.png, where the admin.png file will be set as profile picture for the user with username 'admin'.

#!/usr/bin/python
# BulkPhotoUpload.py
#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:\BulkUploadPhoto\UserPhotos' # From where pictures of the users are read
#Destination Directory must be specified
destination = 'C:\BulkUploadPhoto\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')
try:
#Must specify the UserName & the Password of the usercontext on which the operation must be performed
token = server.confluence2.login('admin', '20605104002');
#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).read())
picName = os.path.basename(userPhoto)
userName = os.path.splitext(picName)[0]
profilePictureAdded = server.confluence2.addProfilePicture(token, userName, picName, 'image/png', pictureData)
if profilePictureAdded:
#Move the uploaded images to the Archive directory
shutil.move(userPhoto, destination)
print "Successfully added profile picture for %d" % userName
else:
print "Failed to add profile picture for %d" % userName
except xmlrpclib.Fault, err:
print "Fault code: %d" % err.faultCode
print "Fault string: %s" % err.faultString


4 answers

1 accepted

This widget could not be displayed.

try this..

  • File Type must be .PNG
  • File name must be the confluence username
#!/usr/bin/python
# BulkPhotoUpload.py
#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')
try:
    #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)
    else:
        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

Thanks Great ... It worked for me..

This widget could not be displayed.
While i run the script  i get the below error
Fault code: 0
Fault string: java.lang.Exception: com.atlassian.confluence.rpc.RemoteException: There was a problem resizing the image
>>>
This widget could not be displayed.

Hi Genius out there, can you please help me out with this query above..

This widget could not be displayed.

Please find the requisites for the above script

  • File Type must be .PNG
  • File name must be the confluence username
  • Image must be of size 48 * 48 pixels

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

431 views 4 6
Join discussion

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