【发布时间】:2015-09-06 07:53:01
【问题描述】:
我正在开发一个移动应用程序,当用户尝试更改图片配置文件时出现错误,经过大量调试后的错误不是在相机中,而是在我尝试发送图像时的文件传输功能中到服务器,没有错误代码或消息,只是应用程序停止工作,这是代码:
$scope.addImage = function (option) {
var options = {
quality: 75,
targetWidth: 300,
destinationType: Camera.DestinationType.DATA_URL,
targetHeight: 300,
saveToPhotoAlbum: false,
correctOrientation: true
};
if (option == 1) {
options.sourceType = Camera.PictureSourceType.CAMERA;
} else {
options.sourceType = Camera.PictureSourceType.PHOTOLIBRARY;
}
$cordovaCamera.getPicture(options).then(function (imageData) {
console.log("IMAGE DATA");
console.log(imageData);
//alert("SUCCESS");
$scope.user.image = "data:image/jpeg;base64," + imageData;
console.log(JSON.stringify($scope.user));
$scope.savePicture();
}, function (err) {
alert("ERRROR");
alert(JSON.stringify(err));
// An error occured. Show a message to the user
});
};
$scope.savePicture = function () {
var options = {
fileKey: "avatar",
fileName: "image.jpg",
chunkedMode: false,
mimeType: "image/jpeg",
headers: {
Authorization: "Bearer " + $auth.getToken()
}
};
$cordovaFileTransfer.upload(api.getApi()+"user/updatephoto", $scope.user.image, options).then(function (result) {
console.log("SUCCESS: " + JSON.stringify(result.response));
}, function (err) {
console.log("ERROR: " + JSON.stringify(err));
alert("ERROR: " + JSON.stringify(err));
}, function (progress) {
// constant progress updates
});
};
感谢您的帮助
【问题讨论】:
-
你看到那个日志了吗:console.log(JSON.stringify($scope.user)); (发生在 savePicture 之前?
-
嗨,在该日志中,一切看起来都很好,错误在一行:$cordovaFileTransfer.upload(api.getApi()+"user/updatephoto", $scope.user.image, options ).then(function (result) 没有错误信息什么的,应用就停止工作了
-
您是否安装了:cordova-plugin-file & cordova-plugin-file-transfer(使用cordova plugin list 命令验证)。我假设你有 ngCordova.js 有相机启动。
-
是的,我已经安装了这个插件:cordova-plugin-crosswalk-webview 1.2.0 "Crosswalk WebView Engine" cordova-plugin-splashscreen 2.0.0 "Splashscreen" cordova-plugin-whitelist 1.0.0 “白名单” org.apache.cordova.camera 0.3.6 “摄像头” org.apache.cordova.file 1.3.3 “文件” org.apache.cordova.file-transfer 0.5.0 “文件传输” org.apache.cordova .inappbrowser 0.6.0 "InAppBrowser"
标签: javascript android cordova ionic-framework cordova-plugins