2

When I try to upload, I get the following error:

Error code:1363030,
msg: Your video upload timed out before it could be completed. This is probably because of a slow network connection or because the video you're trying to upload is too large. Please try again.

I'm using Facebook Javascript SDK 2.5. What am I missing or wrong?

<script>
      var files;
      var fileData = '';  
      function handleFileSelect(evt) {
        files = evt.target.files; // FileList object
        var input = evt.target;
        var reader = new FileReader();
        reader.onload = function (e) {
          fileData = e.target.result;
        };
        reader.readAsDataURL(input.files[0]);
        // files is a FileList of File objects. List some properties.
        var output = [];
        for (var i = 0, f; f = files[i]; i++) {
          output.push('<li class="list-group-item">', escape(f.name), '(', f.type || 'n/a', ') - ',
                      f.size, ' bytes','</li>');
        }
        document.getElementById('list').innerHTML = output.join('');
      }
      document.getElementById('files').addEventListener('change', handleFileSelect, false);

      $(document).ready(function()
      {

        $("#upload").click(function(){
          var token = $('#token').val();
          FB.api(
            "/me/videos",
            "POST",
            {    
                "access_token" : token,
                "title" : 'test',
                "source": fileData
            },
            function (response) {
              if (response && !response.error) {
                /* handle the result */
              }
            }
          );
        })

    });
</script>

here is the sample site

John Corbi
  • 21
  • 3
  • So is your video too large or do you have slow upload speeds? – Jaromanda X Jan 14 '16 at 06:11
  • its small less 200kB for the test i upload this is my speedtest http://www.speedtest.net/my-result/4995493200 – John Corbi Jan 14 '16 at 06:45
  • Not regarding the actual problem here, just a hint: You can have the data generation a lot simpler, if you just use a [`FormData`](https://developer.mozilla.org/de/docs/Web/API/FormData) object. That way, you don’t have to read the file contents yourself, make data URIs of it etc. – CBroe Jan 14 '16 at 10:09
  • If you're "rolling your own" solution or upgrading a legacy SDK, you'll get this error message if you provide the upload data in the wrong field or format. For us, the fix was making sure we were using `new CurlFile()` for `source`. Might be something to check! [(Related)](https://developers.facebook.com/bugs/504112269933280/) – rinogo Aug 29 '17 at 21:48

1 Answers1

2

Just hit this in Node.js. This Facebook error occurs if you don't specify the content type and file name of the attached file (i.e. if you pass it as an inline field value, not as an attached file).

Not sure how to do it via FB.api, but with request-promise module (and ES7 async functions via Babel) it looks like this:

import request from 'request-promise'

async function uploadVideoToFacebook (buf) {
  let url = 'https://graph-video.facebook.com/v2.5/' + pageId + '/videos?access_token=' + pageToken

  let formData = {
    title: 'Video title',
    description: 'Timeline message...',
    source: {
      value: buf,
      options: {
        filename: 'video.mp4',
        contentType: 'video/mp4'
      }
    }
  }

  return await request({ method: 'POST', url, formData })
}

and with XMLHttpRequest on the client-side you would do something like:

var blob = new Blob(videoDataHere, { type: 'video/mp4' })

var formData = new FormData();
formData.append('source', blob);
formData.append('message', 'Spartan Overlay');

var ajax = new XMLHttpRequest()
ajax.onreadystatechange = ...
ajax.open('POST', 'https://graph.facebook.com/' + userId + '/videos?access_token=' + accessToken, true)
ajax.send(formData)
Andrey Tarantsov
  • 8,965
  • 7
  • 54
  • 58