tumblr / docs

Tumblr's public platform documentation.
Apache License 2.0
108 stars 26 forks source link

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

Open bennworks opened 2 years ago

bennworks commented 2 years ago

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 commented 2 years ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

@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 commented 11 months ago

this sounds like a bug in your HTTP library or client code then, unfortunately

On Mon, Sep 18, 2023, 7:07 PM Ben @.***> wrote:

@sirreal https://github.com/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'.

— Reply to this email directly, view it on GitHub https://github.com/tumblr/docs/issues/87#issuecomment-1724644683, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABZCV2WGBGSMVPN46ZZNADX3DO3XANCNFSM5YBCPE7Q . You are receiving this because you are subscribed to this thread.Message ID: @.***>

bennworks commented 11 months ago

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.