import requests


def upload_file(bucket_url, token, record_id, fpath):
    """Upload file to selected record

    Parameters
    ----------
    bucket_url : str
        The url for the file bucket to which upload files
    token : str
        The authentication token for the zenodo or sandbox api
    record_id : str
        The id for record we want to upload files to
    fpath : str
        The path for file to upload

    Returns
    -------
    r : requests object
      The requests response object

    """

    headers = {"Content-Type": "application/octet-stream"}
    with open(fpath, "rb") as fp:
        r = requests.put(
            f"{bucket_url}/{fpath}",
            data=fp,
            params={'access_token': token},
            headers=headers)
    return r