def send_file(name, content_type, stream, node, user, create=True, path='/'):

    if not node:
        return
    node_id = node._id

    if not user:
        return
    cookies = {website_settings.COOKIE_NAME:user.get_or_create_cookie()}

    # create a new folder
    if stream is None:
        upload_url = util.waterbutler_api_url_for(node_id, 'osfstorage', path, kind='folder', name=name)
        print('create folder: url={}'.format(upload_url))
        resp = requests.put(
            upload_url,
            headers={'Content-Type': content_type},
            cookies=cookies,
        )
        if resp.status_code != 201:
            resp.raise_for_status()
        return resp

    # create or update a file
    stream.seek(0)
    if create:
        upload_url = util.waterbutler_api_url_for(node_id, 'osfstorage', path, kind='file', name=name)
        print('create file: url={}'.format(upload_url))
    else:
        path = '/{}'.format(name)
        upload_url = util.waterbutler_api_url_for(node_id, 'osfstorage', path, kind='file')
        print('update file: url={}'.format(upload_url))
    resp = requests.put(
        upload_url,
        data=stream,
        headers={'Content-Type': content_type},
        cookies=cookies,
    )

    if resp.status_code not in [200, 201, 503, 409]:
        resp.raise_for_status()
    if resp.status_code == 503:
        pass  # forward 503 error back to the caller
    elif resp.status_code == 409:
        print('I/O Warning: cannot create new file/folder that already exists.') # this should never appear
    return resp
Formulate proper GetFeature request using KVP encoding
dataset/ETHPy150Open CenterForOpenScience/osf.io/scripts/analytics/utils.py/send_file--crossover with--dataset/ETHPy150Open geopython/OWSLib/owslib/feature/__init__.py/WebFeatureService_.getGETGetFeatureRequest