使用plus.uploader.createUpload,拍照、从相册选取图片上传都没有问题,但录音和录像上传,显示上传成功,但服务器上没有找到上传的文件。是不是plus.uploader.createUpload不能上传音频视频文件???
- 发布:2018-01-28 16:44
- 更新:2018-01-30 21:28
- 阅读:2117
plus.uploader.createUpload无法上传录音录像
海扬波 (作者)
后端应该也没有问题,通过INPUT FILE提交各类文件均能上传。但通过plus.uploader.createUpload,只能上传图片,录音录像上传均不成功。谢谢您的回答,我把代码贴出来,帮我们看一下。
<script>
var cmr=null;
// 录像
function videoCapture() {
var cmr = plus.camera.getCamera();
cmr.startVideoCapture( function ( p ) {
plus.io.resolveLocalFileSystemURL( p, function( entry) {
Upload_Local(entry.toLocalURL(),"video");
}, function( e ) {
alert( "读取录像文件错误:"+e.message );
} );
}, function( e ){
alert( "录像失败:"+e.message );
});
}
//录音
var ev = null;
var r = null;
var timeOutEvent=0;
function startRecord(){
timeOutEvent = 0;
r = plus.audio.getRecorder();
r.record( {filename:"_doc/audio/"}, function (p) {
plus.io.resolveLocalFileSystemURL( p, function( entry) {
Upload_Local(entry.toLocalURL(),"audio");
}, function( e ) {
alert( "读取录音文件错误:"+e.message );
});
}, function ( e ) {
alert( "录音失败: " + e.message );
});
}
function stopRecord(e) {
e = e || window.event;
ev = e.type;
r.stop();
}
// 拍照
function get_Image(divid) {
var cmr = plus.camera.getCamera();
cmr.captureImage(function(p) {
plus.io.resolveLocalFileSystemURL(p, function(entry) {
Upload_Local(entry.toLocalURL(),"pic");
}, function(e) {
plus.nativeUI.toast("读取拍照文件错误:" + e.message);
});
});
}
//相册选取图片
function gallery_Img(divid) {
plus.gallery.pick( function(p){
plus.io.resolveLocalFileSystemURL(p, function(entry) {
Upload_Local(entry.toLocalURL(),"pic");
}, function(e) {
plus.nativeUI.toast("读取拍照文件错误:" + e.message);
});
});
}
function Upload_Local(url,uptype) {
var urlname = url.substr(url.lastIndexOf('/')+1);
var saveurl = "http://www.xxxx.com/TempFiles/" + urlname;
var task = plus.uploader.createUpload( "http://www.xxxx.com/Upload.asp",
{ method:"POST" },
function ( t, status ) {
plus.nativeUI.closeWaiting();
if ( status == 200 ) { // 上传完成
alert( "Up|"+saveurl+"|clo|"+url+"|cc|"+t.url+"|ess: " + t.responseText );
switch(uptype){
case "pic":
$("#sContent").html('<img src=" '+saveurl+' " width="'+ $(window).width() +'" />'+url);
break;
case "video":
$("#sContent").html('<video src=" '+saveurl+' " controls="controls" width="'+ $(window).width() +'"></video>'+url);
break;
case "audio":
$("#sContent").html('<audio src="'+saveurl+'" controls="controls"></audio><audio src="'+url+'" controls="controls"></audio>'+url);
break;
default:
$("#sContent").html('<a href="'+saveurl+'" target=_blank><img src="images/downs.gif" />'+urlname+'</a>'+url);
break;
}
} else {
alert( "上传失败: " + status );
}
});
task.addFile(url, {key:"testdoc"} );
task.start();
}
$(function(){
$("#btAudio").on({
touchstart: function(e){
timeOutEvent = setTimeout(function(){
$("#divAudio").css('display','block');
startRecord();
}, 500);//这里设置长按响应时间
},
touchmove: function(e){
clearTimeout(timeOutEvent);
timeOutEvent = 0;
stopRecord(e);
$("#divAudio").css('display','none');
},
touchend: function(e){
clearTimeout(timeOutEvent);
if(timeOutEvent!=0){
alert("你这是点击,请按住说话! ");
}else{
stopRecord(e);
$("#divAudio").css('display','none');
timeOutEvent = 0;
}
return false;
}
})
});
</script>
一品轩
图片能上传成功,录音和视频上传不了啊,怎么办
2018-08-22 14:50