def get_text_or_binary(filename):
    """Read the first 1024 and attempt to decode it in utf-8. If this succeeds,
    the file is determined to be text. If not, its binary."""
    with open(filename, 'rb') as f:
        chunk = f.read(1024)
    try:
        chunk.decode('utf-8')
        return 'text/plain'
    except UnicodeDecodeError:
        return 'application/octet-stream'