Upload a fileobject to path, HTTP POST-ing to up.jottacloud.com, using the JottaCloud API

def up(self, path, fileobject, upload_callback=None, resume_offset=None):
        "Upload a fileobject to path, HTTP POST-ing to up.jottacloud.com, using the JottaCloud API"
        """

        *** WHAT DID I DO?: created file
        ***

        POST https://up.jottacloud.com/jfs/**USERNAME**/Jotta/Sync/testFolder/testFile.txt?cphash=d41d8cd98f00b204e9800998ecf8427e HTTP/1.1
        User-Agent: Desktop_Jottacloud 3.0.22.203 Windows_8 6.2.9200 x86_64
        Authorization: Basic ******************
        X-JottaAPIVersion: 2.2
        X-Jfs-DeviceName: **CENSORED**
        JCreated: 2014-10-26T12:33:09Z+00:00
        JModified: 2014-10-26T12:33:09Z+00:00
        JMd5: d41d8cd98f00b204e9800998ecf8427e
        JSize: 0
        jx_csid: dOq1NCRer6uxuR/bFxihasj4QzBU3Tn7S2jVF1CE71YW1fGhxPFYYsw2T0XYjnJBtxKQzhWixmg+u5kp8bJtvMpIFHbhSDmPPSk+PVBf2UdFhXxli4YEII9a97eO4XBfn5QWAV1LJ2Z9l59jmnLkJQgfOyexkuQbxHdSLgQPXu8=
        jx_lisence: M1v3p31oQf2OXvyAn2GvfS2I2oiMXrw+cofuMVHHI/2K+wlxhj22VkON6fN6fJMsGNcMzvcFYfmKPgL0Yf8TCO5A/6ULk6N8LctY3+fPegx+Jgbyc4hh0IXwnOdqa+UZ6Lg1ub4VXr5XnX3P3IxeVDg0VbcJnzv4TbFA+oMXmfM=
        Content-Type: application/octet-stream
        Content-Length: 0
        Connection: Keep-Alive
        Accept-Encoding: gzip
        Accept-Language: nb-NO,en,*
        Host: up.jottacloud.com
        """
        url = path.replace('www.jottacloud.com', 'up.jottacloud.com')
        # Calculate file length
        fileobject.seek(0,2)
        contentlen = fileobject.tell()

        # Rewind read head to correct offset
        # If we're resuming an incomplete upload, continue from that offset
        try:
            fileobject.seek(resume_offset)
        except TypeError as e:
            if resume_offset is None:
                fileobject.seek(0)
        except IOError as e:
            log.exception(e)
            log.warning('Could not seek to file offset %r, re-starting upload of %r from 0',
                        resume_offset,
                        url)
            fileobject.seek(0)


        # Calculate file md5 hash
        md5hash = calculate_md5(fileobject)

        log.debug('posting content (len %s, hash %s) to url %r', contentlen, md5hash, url)
        try:
            mtime = os.path.getmtime(fileobject.name)
            timestamp = datetime.datetime.fromtimestamp(mtime).isoformat()
        except Exception as e:
            if hasattr(fileobject, 'name'):
                log.exception('Problems getting mtime from fileobjet: %r', e)
            timestamp = datetime.datetime.now().isoformat()
        params = {'cphash': md5hash}
        m = requests_toolbelt.MultipartEncoder({
             'md5': ('', md5hash),
             'modified': ('', timestamp),
             'created': ('', timestamp),
             'file': (os.path.basename(url), fileobject, 'application/octet-stream'),
        })
        headers = {'JMd5':md5hash,
                   'JCreated': timestamp,
                   'JModified': timestamp,
                   'X-Jfs-DeviceName': 'Jotta',
                   'JSize': str(contentlen), # headers have to be strings or bytes , cf #122
                   'jx_csid': '',
                   'jx_lisence': '',
                   'content-type': m.content_type,
                   }
        fileobject.seek(0) # rewind read index for requests.post
        files = {'md5': ('', md5hash),
                 'modified': ('', timestamp),
                 'created': ('', timestamp),
                 'file': (os.path.basename(url), fileobject, 'application/octet-stream')}
        return self.post(url, None, files=files, params=params, extra_headers=headers, upload_callback=upload_callback)