tumblr / docs

Tumblr's public platform documentation.
Apache License 2.0
109 stars 27 forks source link

/posts POST end point returns error when posting a video file via multipart/form-data #88

Closed bennworks closed 1 year ago

bennworks commented 2 years ago

The multipart form request is failing when creating a new post containing a video file. The returned error is following.

{
    "meta": {"status": 400,"msg": "Bad Request"},
    "response": [],
    "errors": [{
        "title": "Bad Request",
        "code": 0,
        "detail": "Measly little error. Try again."
    },{same error},{same error},{same error}]
}

But detail is changing slightly whenever making a new request like this:

{"title":"Bad Request","code":0,"detail":"Internet strangeness. Try again."}
{"title":"Bad Request","code":0,"detail":"Hit a glitch. Try again."}
{"title":"Bad Request","code":0,"detail":"Something broke. Try again."}
{"title":"Bad Request","code":0,"detail":"Something flubbed. Try again."}
{"title":"Bad Request","code":0,"detail":"Measly little error. Try again."}
{"title":"Bad Request","code":0,"detail":"Minor hiccup. Try again."}

My multipart form request is as following.

content-type    multipart/form-data; charset=utf-8; boundary=END_OF_PART
content-length  1058135

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

{
    "state": "draft",
    "content": [
        {
            "media": [
                {
                    "height": 1280,
                    "identifier": "randomstring",
                    "type": "video/mp4",
                    "width": 720
                }
            ],
            "type": "video"
        }
    ],
    "layout": [
        {
            "type": "rows",
            "display": [
                {
                    "blocks": [
                        0
                    ]
                }
            ]
        }
    ]
}
--END_OF_PART
Content-Disposition: form-data; name="randomstring"; filename="filename.MOV"
Content-Type: video/mp4

{file data}
--END_OF_PART--

PS. Additionally, when posting image files using the same method, it succeeds. The multipart form request is nearly the same content except Content-Type and file data.

cyle commented 2 years ago

Hey @bennworks -- we'll take a look at this and get back to you about this and #87, they're likely related. Thank you for all of the detail here!

bennworks commented 2 years ago

Hey @bennworks -- we'll take a look at this and get back to you about this and #87, they're likely related. Thank you for all of the detail here!

It's been a month already. I wonder when it will be resolved.

bennworks commented 1 year ago

Hi @cyle I'm still desperately waiting for this issue to be resolved. Also, please check if the cause of the problem is because "oauth 1" is used.

sirreal commented 1 year ago

I've also been struggling with this while implementing an NPF post creation method for Tumblr.js (https://github.com/tumblr/tumblr.js/issues/165).

Basic post creation works fine, but as soon as I try to upload media as part of the request is fails.

I've been following the documentation here:

In order to support user uploaded media (photos, videos, etc.), the creation and edit routes also support a multi-part form request where the first part contains the JSON body and subsequent parts contain media data. The Content-Type: multipart/form-data header must be used in this case.

To specify which media data pertains to which block, we use a unique identifier in the JSON body and this identifier is used as the key in the form data. …

--TumblrBoundary
Content-Disposition: form-data; name="json"
Content-Type: application/json

{JSON encoded parameters}
--TumblrBoundary
Content-Disposition: form-data; name="some-identifier"; filename="filename.jpg"
Content-Type: image/jpeg

{image data}
--TumblrBoundary--
sirreal commented 1 year ago

I was able to get this working for tumblr.js, there's an integration test example with a video upload. The request we send looks a lot like the example you shared @bennworks. Were you able to get this working?

If you're using Node.js, you might try with a v4 release of tumblr.js (currently prerelease, but available on npm tagged next).

bennworks commented 1 year ago

Thank @sirreal for providing information. Unfortunately, I'm still stuck with this issue. I'm developing in mobile platform. So I can't use tumblr.js. BTW, do you use oAuth1 or oAuth2? I'm using oAuth1 and I'm wondering if the authentication method has anything to do with this issue.

sanmai commented 1 year ago

Error 400 probably means authentication method is not the problem.

sirreal commented 1 year ago

I've been using oauth1 to successfully create NPF posts.

@bennworks one idea is to capture a request made using tumblr.js to create a post, then compare that with your requests.

sirreal commented 1 year ago

How big are the videos? Size, length, etc. There are limits on videos described here: https://help.tumblr.com/hc/en-us/articles/231455628-Posting-Video

Are you able to upload the same videos via the web editor?

bennworks commented 1 year ago

@sirreal I've tested various video files such as exact video downloaded from Tumblr, small size etc. I have no problem in uploading multipart image data with the same module. And I have captured the upload data stream for various apps(mine and Tumblr one). Captured data shows no problem.

bennworks commented 1 year ago

@cyle , @sirreal I found the cause of this bug finally. The media property of video content is not 'Array' type. It's a single entity with {} only. After removing array, video upload works normally. I use same module for image/video, so I didn't notice until now. Thank you for your help so far.