0

I'm using NodeJS to upload a directory of mp4s one-by-one to Azure. For some reason, the video indexing stalls about 20% of the time. I'm not clear as to why. There are no errors displayed by the API call. When trying to load data for the video, I just get the status "Processing", but it never ends. I have to manually delete the video and start over.

Logging into the videoindexer.ai website, I can see that the process is stalled indefinitely:

video indexer stalling at 30% and 90%

Here is my NodeJS for uploading an MP4. I'd greatly appreciate any advice if I'm doing something wrong here:

const fs = require('fs');
const path = require('path');
const fetch = require('node-fetch');
const FormData = require('form-data');

const uploadVideo = async (filePath) => {
  const fileName = path.parse(filePath).name;

  const url = `https://api.videoindexer.ai/${LOCATION}/Accounts/${ACCOUNTID}/Videos?accessToken=${TOKEN}&name=${fileName}&description=TEST&privacy=private&partition=some_partition`;

  const fileBase = path.parse(filePath).base; // e.g. "video1.mp4"
  const formData = new FormData();
  formData.append('file', fs.createReadStream(filePath), { filename: fileBase });

  const headers = {
    'x-ms-client-request-id': '',
    'Ocp-Apim-Subscription-Key': APIKEY,
    ...formData.getHeaders()
  };

  const response = await fetch(url, {
    cache: 'no-cache',
    headers,
    method: 'POST',
    body: formData
  });
  const json = await response.json();
  if (json.ErrorType && json.Message) {
    throw new Error(`${json.ErrorType} - ${json.Message}`);
  }
  console.log('Successfully uploaded video');
  console.log(json);
  return json.id;
};
uploadVideo('./video1.mp4').then((videoId) => console.log('result: ' + videoId)) // <- returns the correct videoId even when process stalls
shackleton
  • 701
  • 1
  • 12
  • 27

1 Answers1

2

Please add header 'Content-Type': 'multipart/form-data'. You can remove the ...formData.getHeaders() and please provide your account Id, and/or videoId that stalls so we can check internally

Thanks, Video Indexer Team

oriziv
  • 54
  • 4
  • This is very helpful, thanks. I actually do have `'multipart/form-data'` in `...formData.getHeader()` along with a boundary. Do you think the boundary is throwing it off? The full header looks like: `'content-type': 'multipart/form-data; boundary=--------------------------770177812273271632859659' }` I ran 30+ videos today and there was no stalling at all. If I do run into it again, I'll post the videoId and my account Id. – shackleton Feb 19 '21 at 00:17