Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

400 bad request with media and media_with_thumbnail methods #6

Closed
ckruse opened this issue Dec 25, 2022 · 1 comment · Fixed by #8
Closed

400 bad request with media and media_with_thumbnail methods #6

ckruse opened this issue Dec 25, 2022 · 1 comment · Fixed by #8

Comments

@ckruse
Copy link

ckruse commented Dec 25, 2022

Hi there,

when trying to upload a picture with the media request I get a 400 bad request response. Doesn't matter if I post to my local test installation or an publicly available Mastodon instance.

Creating a status w/o medium works.

This is my code:

    let toml_path = env::var("MASTODON_TOML").expect("env variable MASTODON_TOML not set");
    let mastodon = Mastodon::from(toml::from_file(toml_path).unwrap());

    let path = format!(
        "{}/{}/original/{}",
        image_base_path(),
        picture.id,
        picture.image_file_name
    );

    let thumbnail_path = format!(
        "{}/{}/thumbnail/{}",
        image_base_path(),
        picture.id,
        picture.image_file_name
    );

    let attachment = mastodon
        .media_with_thumbnail(path, thumbnail_path, picture.alt.clone())
        .await
        .map_err(|e| {
            println!("Error uploading media: {}", e);
            e
        })?;

That produces this error message:

Error uploading media: Api { status: 400, response: ApiError { error: "Bad Request", error_description: None } }

Am I doing something wrong or is this a bug in the library?

Best regards,
CK

@dscottboggs
Copy link
Owner

Confirmed, this also happens with the upload_photo example. Investigating.

I saw this corresponding log in my server:

mastodon-web-1  | [ae65f280-13b2-4c2f-a77c-6e56f7950df5] ActionController::BadRequest (Invalid request parameters: Invalid encoding for parameter: �PNG
mastodon-web-1  | ▒
IHDĉ�iCCPICC profile(�}�=H�P�OS�";Hq�P�.*�X�P�
mastodon-web-1  | �Vh���Ф%Iqq\
�L'R6�*�^!"B5QaVmN�S�]_��.Ƴ������ŀ�Dg5�&� �ٴk���ì�h���&5H��u��7�E��63�y�0�T�b��Y�ԉ����nP���X��Y��Y�O�B1o�,s�jI,b        2$����
mastodon-web-1  | l�h7H����?��er��*��cU�P\?����U��������8�@hh5���qZ'@��2:�j��$��ѢG��6pq���=�r▒~�)��JA*�P���r��-п�ͭ}�� C�J���X���}���=�����fr��E��bKGD�������     pHYs.#.#x�?vtIME�
                                                                                                                                                                                 ▒
                                                                                                                                                                                  *S ▒tEXtCommentCreated with GIMPW�
                         IDA�c`�&�IEND�B`�):
mastodon-web-1  | [ae65f280-13b2-4c2f-a77c-6e56f7950df5]   
mastodon-web-1  | [ae65f280-13b2-4c2f-a77c-6e56f7950df5] lib/mastodon/rack_middleware.rb:9:in `call'

I think I know how to fix this, if I'm right I'll have a patch in a little while

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants