Asked 1 month ago by MeteoricWanderer001
Why does my Dailymotion API upload report success but the video never appears?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by MeteoricWanderer001
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
I'm trying to automate video uploads to Dailymotion using their API, but although the API responses indicate that the video is uploaded and published, the video never shows up on the site nor encodes properly. I can upload manually on the frontend without issues, and the same access token works when querying manually uploaded videos. However, videos uploaded programmatically remain in a processing state with encoding_progress at 0 and published set to false.
I’ve tried the one-step approach as outlined in the Dailymotion docs, which should upload and publish in a single request, like this:
JAVASCRIPTapp.post('/api/dailymotion/upload', async (req, res) => { const localVideoDirectory = path.join(__dirname, 'videos'); try { const videos = fs.readdirSync(localVideoDirectory) .filter(file => file.endsWith('.mp4') || file.endsWith('.mkv') || file.endsWith('.avi')) .map(file => ({ name: file, path: path.join(localVideoDirectory, file) })); if (!videos || videos.length === 0) { return res.status(400).send('No video files found in the local directory.'); } console.log('[📂] Found Local Videos:', videos); const token = await getAccessToken(); const uploadResults = await Promise.all(videos.map(async (video) => { try { console.log(`[📂] Preparing to upload video: ${video.name}`); const videoData = fs.readFileSync(video.path); const form = new FormData(); form.append('file', videoData, video.name); form.append('title', video.name); form.append('channel', 'music'); form.append('published', 'true'); form.append('is_created_for_kids', 'false'); // Make the request to upload and publish in one step const uploadResponse = await axios.post( `${DAILY_API_BASE}/me/videos`, form, { headers: { Authorization: `Bearer ${token}`, ...form.getHeaders(), }, maxContentLength: Infinity, maxBodyLength: Infinity, } ); console.log('[✅] Video Uploaded and Published:', uploadResponse.data); return uploadResponse.data; } catch (error) { console.error(`[❌] Error uploading video (${video.name}):`, error.message); return { error: error.message, video: video.name }; } })); res.json(uploadResults); } catch (error) { console.error('[❌] Error in upload endpoint:', error.message); res.status(500).send('Error uploading videos.'); } });
The API explorer returns a successful JSON response similar to:
JSON[✅] Video Uploaded and Published: { id: 'x9cqoek', title: 'anpr.mp4', channel: 'music', owner: 'x369ws4' }
However, querying the video status (using curl commands) shows:
BASHcurl -X GET -H "Authorization: Bearer <AUTH_TOKEN>" https://api.dailymotion.com/video/x9cqoek?fields=id,title,channel,status,published
which returns:
JSON{"id":"x9cqoek","title":"anpr.mp4","channel":"music","status":"processing","published":false}
and the encoding progress remains at 0:
BASHcurl -X GET -H "Authorization: Bearer <AUTH_TOKEN>" https://api.dailymotion.com/video/x9cqoek?fields=encoding_progress
I also attempted the two-step approach (first obtaining an upload URL, uploading the video file to it, then publishing using that URL) as shown below:
JAVASCRIPTapp.post('/api/dailymotion/upload', async (req, res) => { const localVideoDirectory = path.join(__dirname, 'videos'); // Local directory for videos try { // Fetch video files from the local directory const videos = fs.readdirSync(localVideoDirectory) .filter(file => file.endsWith('.mp4') || file.endsWith('.mkv') || file.endsWith('.avi')) // Filter video files .map(file => ({ name: file, path: path.join(localVideoDirectory, file) })); if (!videos || videos.length === 0) { return res.status(400).send('No video files found in the local directory.'); } console.log('[📂] Found Local Videos:', videos); const token = await getAccessToken(); const channelId = await getChannelId(); const uploadResults = await Promise.all(videos.map(async (video) => { try { console.log(`[📂] Reading video file: ${video.path}`); // Read video file as a Buffer const videoData = fs.readFileSync(video.path); // Step 1: Get the upload URL from Dailymotion const uploadUrlResponse = await axios.get(`${DAILY_API_BASE}/file/upload`, { params: { access_token: token }, }); const uploadUrl = uploadUrlResponse.data.upload_url; console.log('[🌐] Upload URL:', uploadUrl); // Step 2: Upload the video to the Dailymotion upload URL const FormData = require('form-data'); const form = new FormData(); form.append('file', videoData, video.name); const uploadResponse = await axios.post(uploadUrl, form, { headers: { ...form.getHeaders() }, maxContentLength: Infinity, maxBodyLength: Infinity, }); console.log('[✅] Upload Response:', uploadResponse.data); if (!uploadResponse.data || !uploadResponse.data.url) { throw new Error('Invalid upload response from Dailymotion'); } // Step 3: Publish the video on Dailymotion console.log('[✅] Publishing video...'); const publishResponse = await axios.post( `${DAILY_API_BASE}/me/videos`, { url: uploadResponse.data.url, title: video.name, channel: 'music', privacy: 'public', published: true, is_created_for_kids: false, }, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', }, } ); console.log('[📤] Published Video:', publishResponse.data); return publishResponse.data; } catch (error) { console.error(`[❌] Error uploading video (${video.name}):`, error.message); return { error: error.message, video: video.name }; } })); res.json(uploadResults); } catch (error) { console.error('[❌] Error uploading videos:', error.message); res.status(500).send('Error uploading videos.'); } });
Despite these attempts—and with manual uploads working fine—the API-uploaded videos never fully propagate. I'm aware that some answers and comments suggest using the endpoint /user/<CHANNEL_ID>/videos
instead of /me/videos
and ensuring correct parameter types, but I haven’t yet found a solution that makes the video fully process and appear on Dailymotion.
Any insights or suggestions to resolve this issue would be appreciated.
Comments 0
•Answers 3
•Views 96
Answer by TychoAI Agent • 1 month ago
Below is a list of potential causes and suggestions to troubleshoot and resolve the issue:
The Dailymotion docs for a one-step upload and publish require you to use an endpoint of the form:
BASHhttps://api.dailymotion.com/user/<CHANNEL_ID>/videos
Action:
Double-check that you are using the proper endpoint. In your code you’re using /me/videos
which may not work the same way. Try switching to /user/<CHANNEL_ID>/videos
(make sure to replace <CHANNEL_ID> with your account’s channel id).
Even though you’re following the docs, sometimes the API may expect certain parameters (like published
) either as booleans or strings.
'true'
for published) are accepted.Even if the initial API response indicates the video is published, you showed that querying returns:
JSON{ "id": "x9cqoek", "title": "anpr.mp4", "channel": "music", "status": "processing", "published": false }
It indicates that the video is still in an encoding/processing state. If encoding never starts it might be an API issue or perhaps the file is not being correctly handled by Dailymotion's backend.
Since the one-step process appears cleaner but isn’t propagating the video, try running the two-step process (upload to get a URL and then publish the video with that URL). Your second snippet showed that approach eventually makes the video appear (even if it might take time to encode).
uploadResponse.data.url
is valid) before requesting publication.Here’s a simplified outline of the two-step process:
JAVASCRIPT// Step 1: Get the upload URL const uploadUrlResponse = await axios.get(`${DAILY_API_BASE}/file/upload`, { params: { access_token: token }, }); const uploadUrl = uploadUrlResponse.data.upload_url; // Step 2: Upload the file const FormData = require('form-data'); const form = new FormData(); form.append('file', videoData, video.name); const uploadResponse = await axios.post(uploadUrl, form, { headers: { ...form.getHeaders() }, maxContentLength: Infinity, maxBodyLength: Infinity, }); // Step 3: Publish the video using the video URL obtained const publishResponse = await axios.post( `${DAILY_API_BASE}/user/${channelId}/videos`, { url: uploadResponse.data.url, title: video.name, channel: 'music', privacy: 'public', published: true, is_created_for_kids: false, }, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', }, } );
Since manual uploads work fine and you’re using the same token, it might not be an authentication issue. However, confirm that the API token used in your programmatic workflow has the necessary scopes for both uploading and publishing videos.
/me/videos
to /user/<CHANNEL_ID>/videos
.By comparing these approaches and ensuring the correct endpoint and parameter formatting, you can narrow down what’s causing the video not to propagate on the site.
If issues persist, contacting Dailymotion support with details (including the API responses) might be necessary.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
Answer by EclipseTracker381 • 1 month ago
Thanks to @PySir I got it working!
You were right. You cannot "Upload & Publish" in one step, the video needs to be first uploaded and then you can 'create a video object' on your channel, then publish it. After uploading a video you can then create the object and publish in one step and thats where I was getting confused as the docs say to 'upload & publish'
Anyways, Here's what I used:
JAVASCRIPTapp.post('/api/dailymotion/upload', async (req, res) => { const localVideoDirectory = path.join(__dirname, 'videos'); try { const videos = fs.readdirSync(localVideoDirectory) .filter(file => file.endsWith('.mp4') || file.endsWith('.mkv') || file.endsWith('.avi')) .map(file => ({ name: file, path: path.join(localVideoDirectory, file), normalizedName: file.replace(/\.[^/.]+$/, '').toLowerCase(), })); if (!videos.length) { return res.status(400).send('No video files found in the local directory.'); } console.log('[📂] Found Local Videos:', videos); const token = await getAccessToken(); const existingVideosResponse = await axios.get(`${DAILY_API_BASE}/me/videos`, { params: { fields: 'title', access_token: token }, }); const existingVideoTitles = existingVideosResponse.data.list.map(video => video.title.toLowerCase().trim() ); console.log('[📂] Existing Dailymotion Videos:', existingVideoTitles); const videosToUpload = videos.filter(video => !existingVideoTitles.includes(video.normalizedName) ); console.log('[📂] Videos to Upload:', videosToUpload); if (!videosToUpload.length) { return res.status(200).send('All videos are already uploaded.\n'); } const uploadResults = await Promise.all(videosToUpload.map(async (video) => { try { console.log(`[📂] Preparing to upload video: ${video.name}`); const uploadUrlResponse = await axios.get(`${DAILY_API_BASE}/file/upload`, { params: { access_token: token }, }); const uploadUrl = uploadUrlResponse.data.upload_url; console.log('[🌐] Upload URL:', uploadUrl); const videoData = fs.readFileSync(video.path); const form = new FormData(); form.append('file', videoData, video.name); const uploadResponse = await axios.post(uploadUrl, form, { headers: { ...form.getHeaders() }, maxContentLength: Infinity, maxBodyLength: Infinity, }); console.log('[✅] Video Uploaded:', uploadResponse.data); const videoUrl = uploadResponse.data.url; const videoName = uploadResponse.data.name; console.warn('[🌐] Video URL for Publishing:', videoUrl); console.warn('[🌐] Video Name for Publishing:', videoName); const publishResponse = await axios.post( `${DAILY_API_BASE}/me/videos`, { url: videoUrl, title: videoName, channel: 'music', published: 'true', is_created_for_kids: 'false', }, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/x-www-form-urlencoded', }, } ); console.log('[✅] Video Published:', publishResponse.data); return publishResponse.data; } catch (error) { console.error(`[❌] Error processing video (${video.name}):`, error.response?.data || error.message); return { error: error.message, video: video.name }; } })); res.json(uploadResults); } catch (error) { console.error('[❌] Error in upload endpoint:', error.message); res.status(500).send('Error uploading videos.'); } });
I need to refactor some things now, making it more comprehensive and fault tolerant and point it back to the cloud instance for finding files automatically and finish some styling. Other than that the core logic is there now and I am able to scan for and upload videos programatically! Thank you very much for your patience @PySir
No comments yet.
Answer by VoidGuide454 • 1 month ago
I think your API call is not correct, here is the document about video uploading, https://developers.dailymotion.com/guides/upload/, you should firstly upload your video to a server in order to have the video url in the response, then create a video object using the url that you get from previous upload response.
No comments yet.
No comments yet.