【发布时间】:2016-11-07 20:16:23
【问题描述】:
我有一个 Ionic 框架,其中加载了 FileTranser 模块,因此我可以拍照并上传。 “拍照”部分效果很好。
当我点击图片以便上传时,它会触发叠加层“正在上传”,然后它会淡出并执行 oncomplete 功能。
问题是实际的上传部分什么都不做。没有错误,没有通知,我的日志中没有任何内容,没有实际的 XHR 资源(或任何资源)。这使得调试非常困难。谁能给我推动正确的方向?
Ps:我在我的 android 上执行此操作,连接到 Chrome 的 debugconsole
$scope.takePicture = function() {
var options = {
quality: 90,
destinationType: Camera.DestinationType.FILE_URL,
sourceType: Camera.PictureSourceType.CAMERA
};
$cordovaCamera.getPicture(options).then(
function(imageData) {
$scope.picData = imageData;
$scope.ftLoad = true;
//~ $localStorage.setItem('fotoUp', imageData);
//~ $localStorage.fotoUp = imageData;
$ionicLoading.show({template: 'Loading picture...', duration:500});
},
function(err){
$ionicLoading.show({template: 'Error loading...', duration:500});
}
)
}
//--------------------------
// Upload the photo
$scope.uploadPicture = function() {
$scope.upload = {};
$ionicLoading.show({template: 'Bezig met uploaden...'});
var fileURL = $scope.picData;
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
options.chunkedMode = true;
var ft = new FileTransfer();
ft.upload(fileURL, "https://www.example.com/recieve_photos.php", viewUploadedPictures, function(error) {
$ionicLoading.show({template: 'connection error...'});
$ionicLoading.hide();
}, options);
}
var viewUploadedPictures = function($) {
$ionicLoading.show({template: 'Get uploaded pictures...'});
$http.get('https://www.example.com/recieve_photos.php')
.then(function (response){
$scope.upload.result = response.data
}).catch(function(error){
$scope.error = error;
});
$ionicLoading.hide();
}
【问题讨论】:
标签: javascript android ionic-framework file-transfer