Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

/posts/{post-id} PUT end point returns error: 5002, multipart/form-data content is invalid #87

Open
bennworks opened this issue Jun 7, 2022 · 8 comments

Comments

@bennworks
Copy link

bennworks commented Jun 7, 2022

When posting to /posts/{post-id} end point using PUT method and npf format, multipart/form-data fails with the follwing error.

{
    "meta": {
        "status": 400,
        "msg": "Bad Request"
    },
    "response": [],
    "errors": [
        {
            "title": "Bad Request",
            "code": 5002,
            "detail": "multipart/form-data content is invalid"
        }
    ]
}

When posting to /posts end point to create a new post with images via multipart form content type, no problem occurs. Multi part form works correctly and posting succeeds.

When posting to /posts/{post-id} end point without multi part form(in other words, with the application/json content type), it works normally. Editing a post succeeds.

But if I add a new image when editing a post and post with the multi part form, it fails with the error message "multipart/form-data content is invalid".

Does "PUT /posts/{post-id} end point" support multi part form?

@bennworks
Copy link
Author

For better understanding, I summarized my multipart form request.

content-type: multipart/form-data; charset=utf-8; boundary=END_OF_PART
authorization: {oauth data}
content-length: 347881

--END_OF_PART
Content-Disposition: form-data; name="json"
Content-Type: application/json; charset=utf-8

{
    "tags": "",
    "state": "draft",
    "content": [
        {
            "type": "text",
            "text": "Test"
        },
        {
            "media": [
                {
                    "height": 1920,
                    "identifier": "randomstring",
                    "type": "image\/jpeg",
                    "width": 1080
                }
            ],
            "type": "image"
        }
    ],
    "layout": [
        {
            "type": "rows",
            "display": [
                {
                    "blocks": [
                        0
                    ]
                },
                {
                    "blocks": [
                        1
                    ]
                }
            ]
        }
    ]
}
--END_OF_PART
Content-Disposition: form-data; name="randomstring"; filename="randomstring.jpeg"
Content-Type: image/jpeg

{file data}
--END_OF_PART--

@bennworks
Copy link
Author

Hi @cyle ,
This issue seems to be not related to #88.(fortunately, #88 has resolved.)
From the error response detail(code:5002, multipart/form-data content is invalid), it seems that the PUT endpoint does not accept 'multipart/form-data' content type at all. Please check this again.

@sirreal
Copy link
Member

sirreal commented Sep 18, 2023

Will you try making media an object instead of an array of objects?

I see

{
            "media": [
                {
                    "height": 1920,
                    "identifier": "randomstring",
                    "type": "image\/jpeg",
                    "width": 1080
                }
            ],
}

expected:

{
            "media": {
                    "height": 1920,
                    "identifier": "randomstring",
                    "type": "image\/jpeg",
                    "width": 1080
            }
}

@bennworks
Copy link
Author

Hi @sirreal , I tried. But the result is not different. The same error(code:5002, multipart/form-data content is invalid) is returned. BTW, all the image requests( POST method for creating post) are successful with the media object instead of array. Is it reliable?

@sirreal
Copy link
Member

sirreal commented Sep 18, 2023

I tested this out and it seems to be working correctly with PUT for NPF edits. Here's what a working request looks like for me:

----------------------------728313216271056798838717
Content-Disposition: form-data; name="4"; filename="image.jpg"
Content-Type: image/jpeg

…binary image data…
----------------------------728313216271056798838717
Content-Disposition: form-data; name="json"
Content-Type: application/json

{"tags":"a-tag","content":[{"type":"image","media":{"identifier":"4"}}]}

@bennworks
Copy link
Author

@sirreal , I have tried exactly the same as yours, but, unfortunately, the result never changes. Whenever I make any change, the response is always '400 bad request, code:5002, multipart/form-data content is invalid'.

@nightpool
Copy link

nightpool commented Sep 19, 2023 via email

@bennworks
Copy link
Author

Hi @nightpool , @sirreal ,
I use 'GTMSessionFetcher'(by Google, latest version). It's very stable and I have no problem when creating(POST method) NPF posts with multipart/form-data and editing(PUT method) NPF posts without multipart/form-data.

I know that the 'api-http2.tumblr.com' endpoint used by the official app works well for PUT/multipart. However, the 'api.tumblr.com' endpoint used by third-party developers seems to work a little differently. After running into this issue, I searched 'put multipart/form-data' on Google and came across many reports that some web server libraries had problems supporting files in the put method (especially on stackoverflow), so I asked you here to check if the PUT/multipart function is working properly. However, since @sirreal 's test says it works normally, I'm not sure what I should look into further.

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

No branches or pull requests

3 participants