我如何上传图片到 Trello 一个 trello,但不将其设置为封面(这是默认设置)

How can I upload and image to Trello a trello, but NOT set it as Cover (which is the default setting)

我正在使用 Trello API 将图像上传到 Trello 卡片。 Trello 默认将图像设置为封面图像。 API 文档说有一个 setCover 选项,但我无法使用它。

https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-attachments-post

def __upload_image_to_card(self, connection: dict, card: dict, image_path : str, cover=False):
    params = (
        ('key', connection['trello_api_key']),
        ('token', connection['trello_api_token']),
    )
    
    values = {
        'file': (image_path, open(image_path, 'rb')),
        'setCover' : (cover),
    }

    # TODO: Move to node_manager
    response = requests.post('https://api.trello.com/1/cards/%s/attachments' % card['id'], params=params, files=values).json()

我试过在布尔值和字符串之间切换,也试过删除括号。我什至在值中添加了一个错误键,以查看是否可以获得不同的响应。 None 阻止了图片的上传,none 阻止了图片成为默认图片。

非常感谢任何帮助。

setCover 应该在 params,而不是 files/values。您可能还需要将其设为 str(cover).lower(),因为它需要 true/false 而不是 True/False.

# since you using a list of tuples:
params = (
    ('key', connection['trello_api_key']),
    ('token', connection['trello_api_token']),
    ('setCover', cover),
)

或作为字典:

params = {
    'key': connection['trello_api_key'],
    'token': connection['trello_api_token'],
    'setCover': cover,
}