Created
          March 18, 2013 13:08 
        
      - 
      
 - 
        
Save Palleas/5187018 to your computer and use it in GitHub Desktop.  
    Upload a file to confluence using python
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/python | |
| from __future__ import with_statement | |
| import sys, string, xmlrpclib, re, os | |
| if len(sys.argv) < 5: | |
| exit("Usage: " + sys.argv[0] + " spacekey pagetitle contentType filename"); | |
| spacekey = sys.argv[1]; | |
| pagetitle = sys.argv[2]; | |
| contentType = sys.argv[3]; | |
| filename = sys.argv[4]; | |
| with open(filename, 'rb') as f: | |
| data = f.read(); # slurp all the data | |
| server = xmlrpclib.ServerProxy('https://your-url/confluence/rpc/xmlrpc'); | |
| token = server.confluence2.login('your-login', 'your-password'); | |
| page = server.confluence2.getPage(token, spacekey, pagetitle); | |
| if page is None: | |
| exit("Could not find page " + spacekey + ":" + pagetitle); | |
| attachment = {}; | |
| attachment['fileName'] = os.path.basename(filename); | |
| attachment['contentType'] = contentType; | |
| server.confluence2.addAttachment(token, page['id'], attachment, xmlrpclib.Binary(data)); | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment