Table of content

Video upload

Uploading a video on your Dailymotion account can be done programmatically using our API. Below are described the different steps to follow in order to successfully upload content on your channel.

Note: a quota applies to video upload, please refer to the rate limit section.

Note for Organizations: All API calls and code samples in this guide can be used to upload content on child channels

Upload and publish videos

1. Authenticate the user

As uploading a video is an action that impacts one’s account, you need to be authenticated with the account on which the video is going to belong to and request the manage_videos scope. See the authentication guide for more information on how to authenticate the user and request an access token for our API calls. You will have to pass the returned access token to each of the following calls.

2. Get an upload URL

Perform a GET request to https://api.dailymotion.com/file/upload to retrieve an upload URL. Don’t forget to provide your access token to the request. The upload_url will be returned along with the progress_url (the endpoint is described in more details at /file/upload).

curl -H "Authorization: Bearer ${ACCESS_TOKEN}" \
     "https://api.dailymotion.com/file/upload"

3. Upload the video

The video can actually be uploaded to the upload_url retrieved above by making a POST HTTP request using the multipart/form-data content type. The video data has to be contained in a file field:

curl -X POST \
     -F 'file=@/path/to/your/video.mp4' \
     '<UPLOAD_URL>'

Once the POST HTTP request is finished, the upload server will return a JSON object containing several fields, you only need the url one for the next steps.

Note:

  • The upload request requires a minimum version of TLS 1.2 protocol
  • If the upload POST fails, you need to reacquire a new upload_url.
  • The upload url does not have an expiry term for uploading, although some activity has to be “seen” on started uploads at least every 4 hours.

4. Create the video

Now that you retrieved your video URL (url field in the returned response), you can perform a POST call using
https://api.dailymotion.com/user/<CHANNEL_ID>/videos
and add the video URL in a url=<URL> field.

This API call will create the video on your channel. The ID of the newly created video will be returned in the response.id field.

curl -X POST -H "Authorization: Bearer ${ACCESS_TOKEN}" \
    -d "url=<URL>" \
     "https://api.dailymotion.com/user/<CHANNEL_ID>/videos"

5. Publish the video

Once the video is created, it doesn’t mean it is published. You have to perform another POST request on https://api.dailymotion.com/video/<VIDEO_ID> URL along with the fields you want to modify. Some fields like titlechannel and is_created_for_kids are mandatory before you can publish the video. Set those fields, and toggle the published field to true to publish the video.

curl -X POST -H "Authorization: Bearer ${ACCESS_TOKEN}" \
     -d 'published=true' \
     -d 'title=<TITLE>' \
     -d 'channel=<CATEGORY>' \ 
     -d "is_created_for_kids=<true|false>" \
     "https://api.dailymotion.com/video/<VIDEO_ID>"

Note: The channel object represents a category of videos. Check the full list of available categories.

Important: You must include the “is_created_for_kids” field to identify whether your video is “created for kids”. It will allow us to address the content to the right audience and help you comply with several laws including COPPA and GDPR.

You can visit our Help Center for more information on how to determine the audience of your video, and check how to use the “is_created_for_kids” mandatory field.

Note:

  • if your video has an external url, you don’t need to upload it to our servers, you can directly use this url as the video source. Skip steps 2 and 3, and directly post the video using the url field (set to your video source url).
  • you can perform steps 4 and 5 in a single HTTP request by passing all the extra information in the initial POST request as follows.
curl -X POST \
     -H "Authorization: Bearer ${ACCESS_TOKEN}" \
     -d 'url=<VIDEO_URL>' \
     -d 'title=Dailymotion cURL upload test' \
     -d 'channel=videogames' \
     -d 'published=true' \
     -d 'is_created_for_kids=false' \
     "https://api.dailymotion.com/user/<CHANNEL_ID>/videos"

Resume function

We provide a resume function for uploading videos. In this case, you have to replace /upload by /rupload in the upload url. The protocol is described in this NGinx module page.


Code samples

PHP
Javascript
Python
$url = $api->uploadFile('/path/to/your/video.mp4');
$api->post(
    '/user/<CHANNEL_ID>/videos',
    array(
        'url'       => $url,
        'title'     => 'My Title',
        'channel'   => 'videogames',
        'published' => true,
        'is_created_for_kids' => false,
    )
);
// get an upload url
DM.api('/file/upload', function (response)
{
    //upload the video and get the url
    var xhr =  new XMLHttpRequest();
    xhr.open('POST', response.upload_url, true);
    var formData = new FormData(document.getElementById("fileDomId"));
    xhr.send(formData);

    // check when video is uploaded
    xhr.onreadystatechange = function ()
    {
        if (xhr.readyState == 4)
        {
            // create the video object and publish the video
            DM.api(
                '/user/<CHANNEL_ID>/videos',
                'post',
                {
                    url: JSON.parse(xhr.response).url,
                    title: 'My Title',
                    channel: 'videogames',
                    published: 'true',
                    is_created_for_kids: 'false'
                }
            );
        }
    }
});
d = dailymotion.Dailymotion()
d.set_grant_type('password', api_key=API_KEY, api_secret=API_SECRET,
    scope=['manage_videos'], info={'username': USERNAME, 'password': PASSWORD})
url = d.upload('./video.mp4')
d.post(
    "/user/<CHANNEL_ID>/videos",
    {
        "url": url,
        "title": "My Title",
        "published": "true",
        "channel": "news",
        "is_created_for_kids": "false",
    },
)