相同方法安卓可以上传,苹果失败 求指导
var files = [];
plus.io.requestFileSystem(plus.io.PRIVATE_DOC, function(fs) {
fs.root.getFile('audio/mcs12.amr', {
create: false
}, function(fileEntry) {
fileEntry.file(function(file) {
var fileReader = new plus.io.FileReader();
files.push({
name: "file",
path: file.fullPath
});
if (files.length <= 0) {
plus.nativeUI.alert("录音文件丢失!请尝试重新录音或者手动输入问题内容!");
return;
}
var wt = plus.nativeUI.showWaiting();
var task = plus.uploader.createUpload("http://192.168.1.1::9294/v1/fileupload/", {
method: "POST"
},
function(t, status) { //上传完成
var state = 0;
if (status == 200) {
var jsonStr = t.responseText.replace(/\\/g, "");
jsonStr = jsonStr.substr(1, jsonStr.length - 2);
var json = eval("(" + jsonStr + ")");
if (json.error == 0) {
state = 1;
$("#yuyin").val(json.fname);
}
}
wt.close();
if (state == 0) {
alert("语音提交失败!请尝试重新录音或者手动输入问题内容!")
} else {
$.ajax({
type: "Get",
url: "http://192.168.1.1:9294/v1/subQuestion/" + $("#questionTitle").val() + "/" + $("#questionContent").val() + "/" + $("#divQuestionType").attr("value") + "/" + bl_Public + "/" + $("#imgPhoto").attr("value") + "/" + $("#yuyin").val() + "/" + localStorage.jlyid,
success: function(data) {
var json = eval(data);
plus.nativeUI.alert(json[0].message);
$("#yuyin").val("false");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
plus.nativeUI.alert("提交失败!请再次尝试");
},
async: true
});
}
}
);
task.addData("client", "HelloH5+");
for (var i = 0; i < files.length; i++) {
var f = files[i];
task.addFile(f.path, {
key: f.name
});
}
task.start();
});
});
});