search

Home  >  Q&A  >  body text

Error 400: "Media type 'application/json; charset=UTF-8' is not supported."

Have fun, I use Google api v3 to upload videos to YouTube. Unfortunately I'm facing this error since yesterday without any changes in the code or server.

I searched for the error text in different sections but didn't get any results. The only thing I found was this package and the file at this address src/Http/MediaFileUpload.php Specify content-type, the value is application/json; set charset=UTF-8. I think that's the problem. Please guide me.

Thanks

Environment details

Steps to reproduce

"error": {
    "code": 400,
    "message": "Media type 'application/json; charset=UTF-8' is not supported. ",
    "errors": [
      {
        "message": "Media type 'application/json; charset=UTF-8' is not supported. ",
        "domain": "global",
        "reason": "badRequest"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }

Code Example

 $chunkSizeBytes = 15 * 1024 * 1024;
        $client->setDefer(true);
        $insertRequest = $youtube->videos->insert("status,snippet,recordingDetails", $video , [
            'notifySubscribers' => true
        ]);
        $media = new MediaFileUpload(
            $client,
            $insertRequest,
            'video/'.File::extension($videoPath),
            null,
            false,
            $chunkSizeBytes
        );
        $media->setFileSize(File::size($videoPath));

        $status = false;
        $handle = fopen($videoPath, "rb");
        while (!$status && !feof($handle)) {
            $chunk = fread($handle, $chunkSizeBytes);
            $status = $media->nextChunk($chunk);
        }
        fclose($handle);

        $client->setDefer(false);

P粉818561682P粉818561682240 days ago397

reply all(1)I'll reply

  • P粉872101673

    P粉8721016732024-03-29 13:54:49

    Looking at the code, the media type application/json occurs when $resumable is false (see here and here).

    So I would try setting $resumable = true (which is the fifth parameter of MediaFileUpload). You can find it at large-file-upload.php.

    reply
    0
  • Cancelreply