Skip to content
Advertisement

Dailymotion API – Can’t get to a video to upload

I can’t manage to get a file to upload the DailyMotion API.

I’m following these steps : https://developer.dailymotion.com/video-upload/upload-new-video-api/

The first API call runs fine and returns me the “upload_url” that I feed into the method you’ll see below.

It fails on the 2nd step and the response error is :

{"error":"missing content size","seal": "[some string]"}

How am I supposed to set the content size ?

the code for the 2nd call :

<?php

namespace PierreMiniggioYoutubeChannelClonerDailymotionAPI;

class DailymotionFileUploader
{

    public function upload(string $uploadUrl, string $filePath): ?string
    {
        $formattedFile = function_exists('curl_file_create')
            ? curl_file_create(str_replace('\', '/', $filePath))
            : sprintf("@%s", $filePath)
        ;

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $uploadUrl);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt(
            $ch,
            CURLOPT_POSTFIELDS,
            ['file' => $formattedFile]
        );
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $response = curl_exec($ch);
        //var_dump($response); die(); // the output I printed above

        curl_close($ch);

        if (empty($response)) {
            return null;
        }
        
        $jsonResponse = json_decode($response, true);

        if (empty($jsonResponse) || ! isset($jsonResponse['url'])) {
            return null;
        }
        
        return $jsonResponse['url'];
    }
}

OS : W10 I made sure the file path and the upload URL are correct.

I tried using the dailymotion/sdk lib and use the function that uploads a file instead of using my curl requests, but I get the exact same error.

Advertisement

Answer

Problem Solved, It was issue with curl/PHP. I was running the script in PHP 7.4.3-dev, updated to 7.4.11 and it solved the issue. More Info about the bug here : https://bugs.php.net/bug.php?id=79013

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement