Video upload

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

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

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).

If you plan to make the end-user post the video on this URL, you can configure a callback URL to have your service called once the upload is finished. Simply add a callback_url=<URL> query string parameter to the URL with the encoded URL as value.

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, two scenarios are possible:

  • If you didn't provide a callback URL, the upload server will return a JSON object.
  • If you did provide a callback URL, it will add several query string parameters to your callback URL.

Either way, the only field you'll need is the url one.

Note:

  • 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

With the video URL you just retrieved (url field in the returned response), you can perform a POST HTTP request to https://api.dailymotion.com/me/videos, with a url=<URL> field. This API call will create the video on your account. The identifier of the newly created video will be returned in the response, in the response.id field.

curl -X POST -H "Authorization: Bearer ${ACCESS_TOKEN}" \
     "https://api.dailymotion.com/me/videos"

If you are an MCN with a specific permissions set by your content manager, you can set your content provider id on videos.

curl -X POST -H "Authorization: Bearer ${ACCESS_TOKEN}" \
     -d "content_provider=YOUR_CONTENT_PROVIDER_NAME" \
     -d "content_provider_id=CONTENT_PROVIDER_ID" \
     "https://api.dailymotion.com/me/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 title, tags and channel 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=<CHANNEL>' \
     -d 'tags=<TAGS>' \
     https://api.dailymotion.com/video/<VIDEO_ID>

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 'tags=dailymotion,api,sdk,test' \
     -d 'channel=videogames' \
     -d 'published=true' \
     "https://api.dailymotion.com/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

$url = $api->uploadFile('/path/to/your/video.mp4');
$api->post(
    '/videos',
    array(
        'url'       => $url,
        'title'     => 'Dailymotion PHP SDK upload test',
        'tags'      => 'dailymotion,api,sdk,test',
        'channel'   => 'videogames',
        'published' => true,
    )
);
// 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(
                '/videos',
                'post',
                {
                    url: JSON.parse(xhr.response).url,
                    title: 'Dailymotion PHP SDK upload test',
                    tags: 'dailymotion,api,sdk,test',
                    channel: 'videogames',
                    published: 'true'
                }
            );
        }
    }
});
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('/me/videos',
    {'url': url, 'title': 'MyTitle', 'published': 'true', 'channel': 'news'})