使用cordova插件上传文件,大家会遇到后台怎么接收数据的问题,这篇文章会前后端结合讲述cordova-plugin-file-transfer的使用;希望能帮助到读者。
1、前端js的调用cordova插件
function onDeviceReady(fileURL) {
var win = function (r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
var fail = function (error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
var options = new FileUploadOptions();
options.fileKey = "file"; // 表单元素的名称。同input标签中的name属性。
options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1); // 文件名称
alert("文件名称"+options.fileName);