Javascript 无法使用PhantomJS/CasperJS使用大文件自动执行Dailymotion上载页面

Javascript 无法使用PhantomJS/CasperJS使用大文件自动执行Dailymotion上载页面,javascript,phantomjs,casperjs,Javascript,Phantomjs,Casperjs,我制作了两个PhantomJS/CasperJS脚本,因为我正在尝试为多个平台开发一个开源视频上传程序 问题是,对于Dailymotion,脚本可以处理小文件,但不能处理大文件 以下是测试PhantomJS脚本: var page = new WebPage(), testindex = 0, loadInProgress = false; page.settings.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38

我制作了两个PhantomJS/CasperJS脚本,因为我正在尝试为多个平台开发一个开源视频上传程序

问题是,对于Dailymotion,脚本可以处理小文件,但不能处理大文件

以下是测试PhantomJS脚本:

var page = new WebPage(), testindex = 0, loadInProgress = false;
page.settings.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0';
page.viewportSize = {
  width: 2560,
  height: 1440
};
page.customHeaders = {
  "Accept": "text/html, application/xhtml+xml, application/xml, q=0.9, */*, q=0.8",
  "Accept-Language": "fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3",
  "Referer": "http://www.dailymotion.com/fr",
  "Access-Control-Allow-Origin": "*"
};
page.onConsoleMessage = function(msg) {
  console.log(msg);
};

page.onLoadStarted = function() {
  loadInProgress = true;
};

page.onLoadFinished = function() {
  loadInProgress = false;
};

page.onError = function(msg, trace) {
    var msgStack = ['ERROR: ' + msg];
    if (trace && trace.length) {
        msgStack.push('TRACE:');
        trace.forEach(function(t) {
            msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : ''));
        });
    }
    // uncomment to log into the console 
    // console.error(msgStack.join('\n'));
};

var steps = [
  function() {
    //Load Login Page
    page.open("http://www.dailymotion.com/widget/upload/?skin=fog");
  },
  function() {
      page.evaluate(function() {
      var form = document.getElementById("login_form");
      form.elements["username"].value="Nemsis1990";
      form.elements["password"].value="20051965";
      form.submit();
    });
  },
function() {
    //Load Login Page
    page.open("http://www.dailymotion.com/upload");
  },
  function() {
    console.log("Uploading file..");
    page.uploadFile('input[type=file]', '/users/jabassar/Desktop/sample2.mp4');
  },
  function () {
    page.render("test.png");
  }
];


interval = setInterval(function() {
  if (!loadInProgress && typeof steps[testindex] == "function") {
    //console.log("Step " + (testindex + 1) + " completed.");
    steps[testindex]();
    testindex++;
  }
  if (typeof steps[testindex] != "function") {
    //console.log("Task finished");
    phantom.exit();
  }
}, 10000);

function waitFor(testFx, onReady, timeOutMillis) {
    var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 30000000, //< Default Max Timout is 3s
        start = new Date().getTime(),
        condition = false,
        interval = setInterval(function() {
            if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
                // If not time-out yet and condition not yet fulfilled
                condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
            } else {
                if(!condition) {
                    // If condition still not fulfilled (timeout but condition is 'false')
                    console.log("'waitFor()' timeout");
                    phantom.exit(1);
                } else {
                    // Condition fulfilled (timeout and/or condition is 'true')
                    console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
                    typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
                    clearInterval(interval); //< Stop this interval
                }
            }
        }, 1000); //< repeat check every 250ms
};
var casper = require('casper').create();

casper.start('http://www.dailymotion.com/widget/upload/?skin=fog', function() {
    casper.fill('form[id="login_form"]', {
        'username': 'Nemsis1990',
        'password': '20051965'
    ,}, true);
    this.wait(2000);
});

casper.thenOpen('http://www.dailymotion.com/upload', function() {
    this.echo(this.getTitle());
});

casper.then(function() {
  this.page.uploadFile('input[type=file]', '/users/jabassar/Desktop/sample2.mp4');
});

casper.then(function() {
  this.wait(30000);
  this.capture('test2.png');
});

casper.run();
因此,它适用于这个小(2mb)文件:

但是这个大文件不起作用:

http://sample-videos.com/video/mp4/720/big_buck_bunny_720p_30mb.mp4
Dailymotion说(javascript日志):

(2.0.0 phantomjs上传文件有漏洞,所以我使用1.9.8)

你能帮帮我吗


PS:PhantomJS必须以--web security=false运行,否则会引发警告。

PhantomJS具有任意限制,上传时间不能超过30秒。也许这和你的问题是一样的。不,它甚至没有开始上传。这可能是相关的,但20KB似乎有点低:不,我以前用phantomjs上传600mb的文件,但这个表单很特殊。
http://sample-videos.com/video/mp4/720/big_buck_bunny_720p_30mb.mp4
CHUNK FAIL [object Object] [object Object]
ERROR!!!!
CHUNK FAIL [object Object] [object Object]
ERROR!!!!
CHUNK FAIL [object Object] [object Object]
ERROR!!!!
CHUNK FAIL [object Object] [object Object]
ERROR!!!!