def _publish_file(token, room, filepath, message='', api_url=None):
 if (not os.path.isfile(filepath)):
  raise ValueError("File '{0}' does not exist".format(filepath))
 if (len(message) > 1000):
  raise ValueError('Message too long')
 url = '{0}/v2/room/{1}/share/file'.format(api_url, room)
 headers = {'Content-type': 'multipart/related; boundary=boundary123456'}
 headers['Authorization'] = ('Bearer ' + token)
 msg = json.dumps({'message': message})
 payload = '--boundary123456\nContent-Type: application/json; charset=UTF-8\nContent-Disposition: attachment; name="metadata"\n\n{0}\n\n--boundary123456\nContent-Disposition: attachment; name="file"; filename="{1}"\n\n{2}\n\n--boundary123456--'.format(msg, os.path.basename(filepath), open(filepath, 'rb').read())
 salt.utils.http.query(url, method='POST', header_dict=headers, data=payload)

def _publish_file ( token , room , filepath , message = '' , api_url = None ) : if ( not os . path . isfile ( filepath ) ) : raise ValueError ( "File '{0}' does not exist" . format ( filepath ) ) if ( len ( message ) > 1000 ) : raise ValueError ( 'Message too long' ) url = '{0}/v2/room/{1}/share/file' . format ( api_url , room ) headers = { 'Content-type' : 'multipart/related; boundary=boundary123456' } headers [ 'Authorization' ] = ( 'Bearer ' + token ) msg = json . dumps ( { 'message' : message } ) payload = '--boundary123456\nContent-Type: application/json; charset=UTF-8\nContent-Disposition: attachment; name="metadata"\n\n{0}\n\n--boundary123456\nContent-Disposition: attachment; name="file"; filename="{1}"\n\n{2}\n\n--boundary123456--' . format ( msg , os . path . basename ( filepath ) , open ( filepath , 'rb' ) . read ( ) ) salt . utils . http . query ( url , method = 'POST' , header_dict = headers , data = payload )
send file to a hipchat room via api version 2 parameters token : str hipchat api version 2 compatible token - must be token for active user room: str name or api id of the room to notify filepath: str full path of file to be sent message: str .