代码之家  ›  专栏  ›  技术社区  ›  Robert

当图像文件名或描述包含非ascii字符时,我如何上传用于在Mastodon上嘟嘟的图像?

  •  0
  • Robert  · 技术社区  · 3 年前

    我想要一个本地文件名包含非ascii(utf8)字符的图像,或者描述包含非ascii字符的图像。

    #!/usr/bin/env perl
    use strict;
    use warnings;
    use utf8;
    use Mastodon::Client;
    use HTML::Entities;
    
    my $client = Mastodon::Client->new(
        client_id => "...",
        client_secret => "...",
        access_token => "...",
        instance => "mstdn.io",
        name => 'PerlBot',
        coerce_entities => 1,
    );
    
    $client->upload_media('logo.png',
        {
            'description' => "Für mich",   # 400 Bad request
    #        'description' => encode_entities("Für mich"),   # 500 internal server error
    #        'description' => 'only ascii',   # ok
        },
    );
    

    如果描述包含,例如,一个,我得到一个HTTP 400坏请求错误。如果我对实体进行HTML编码,我会得到一个HTTP500内部服务器错误。当描述只包含ASCII字符时,它会起作用,但这真的很不方便。

    与本地图像文件名相同;如果我有例如“lg.png”而不是“logo.png”,我也会得到HTTP 400错误。

    这个 official API documentation 没有说明任何关于字符编码的内容,也没有 the Mastodon::Client documentation

    如果文件的名称和描述包含非ASCII字符,特别是utf8字符,我该如何toot文件?

    0 回复  |  直到 3 年前