0
我有PhoneGap奇怪的问题,我试图从应用程序记录视频,并将其上传到服务器。PhoneGap视频记录并上传到服务器
app.initialize();
$(function(){
//capture callback
var captureSuccess = function(mediaFiles) {
var i, len;
for(i = 0, len = mediaFiles.length; i < len; i += 1) {
uploadFile(mediaFiles[i]);
}
};
function uploadFile(mediaFiles) {
var options = new FileUploadOptions();
options.fileKey = 'file';
options.fileName = mediaFiles.name;
options.contentType = 'video/mp4';
options.mimeType = mediaFiles.type;
options.chunkedMode = true;
var ft = new FileTransfer();
var path = mediaFiles.fullPath;
//var name = mediaFiles.name;
ft.upload(path,
'http://domainName/~me/upload.php',
function(result) { //success callback
navigator.notification.alert('Path: ' + path + ' bytesSent: ' + result.bytesSent + ' responseCode: ' + result.responseCode + ' response: ' + result.response, null, 'Upload Error');
$("#infoMessage").html('Success!');
},
function(error) { //error callback
navigator.notification.alert('Error uploading file ' + path + ', Error code: ' + error.code + ' Target: ' + error.target + ' http_status: ' + error.http_status + ' Body: ' + error.body + ' Exception: ' + error.exception.toString(), null, 'Upload Error');
$("#infoMessage").html('Problem')
},
options);
}
// capture error callback
var captureError = function(error) {
navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
};
//start video capture
var accessCamera = function() {
navigator.device.capture.captureVideo(captureSuccess, captureError, { limit:1 });
};
$("#cambtn").on('click', accessCamera);
服务器端正在运行,因为它应该用邮递员应用程序进行测试。 回应,我从PhoneGap的应用“成功回调”得到的是:Screenshot
服务器端脚本是如此基本的现在:
$target_dir = "uploads/";
if(isset($_FILES['file'])) {
$target_file = $target_dir . basename($_FILES["file"]["name"]);
move_uploaded_file($_FILES['file']['tmp_name'], $target_file);
}
print_r($_FILES); //This line returns empty array when request is send by the application but it returns array with data when I test it with Postman.
die();
问题是由于chunkedMode选项。它必须设置为false。
这最后一个参数只是一个弹出通知的标题,你可以在截图这么看,这不是问题在所有。 – xcentric
不好意思误解了你的问题。在看到代码中的注释以解释错误之前,我在图片上看到了“上传错误”。我会检查android监视器和服务器日志。你可以让php写一个日志并在那里排除故障。我正在看http://stackoverflow.com/questions/29099303/uploading-file-over-https-with-cordova-filetransfer并试图查看是否有可能成功块被调用,即使有错误如果该网址没有被列入白名单或类似的东西, –
也检查标题('访问控制,允许来源:*');在你的php –