ionic FileTransfer 不提供 result/errors/feedback,然后执行成功功能
ionic FileTransfer gives no result/errors/feedback, and then does do the success function
我有一个 Ionic 框架,我在其中加载了 FileTranser 模块,因此我可以拍照并上传。 'take a picture' 部分完美运行。
当我单击图片以便上传时,它会触发叠加层 "Busy uploading",然后它会淡出并执行 oncomplete 函数。
问题是实际的上传部分什么也没做。没有错误,没有通知,我的日志中没有任何内容,没有实际的 XHR 资源(或任何资源)。这使得调试变得非常困难。谁能给我一个正确方向的推动?
Ps:我正在我的 android 上执行此操作,连接到 Chrome 的调试控制台
$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();
}
我找到了其他文档,其中展示了如何使用 result/response 进行更多调试:
var win = function (r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
$ionicLoading.hide();
}
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);
$ionicLoading.hide();
}
var ft = new FileTransfer();
ft.upload(fileURL, encodeURI("https://www.example.com/recieve_photos.php"), win, fail, options);
在那之后,我知道我得到了错误代码 3,这让我可以继续进行。
我有一个 Ionic 框架,我在其中加载了 FileTranser 模块,因此我可以拍照并上传。 'take a picture' 部分完美运行。
当我单击图片以便上传时,它会触发叠加层 "Busy uploading",然后它会淡出并执行 oncomplete 函数。
问题是实际的上传部分什么也没做。没有错误,没有通知,我的日志中没有任何内容,没有实际的 XHR 资源(或任何资源)。这使得调试变得非常困难。谁能给我一个正确方向的推动?
Ps:我正在我的 android 上执行此操作,连接到 Chrome 的调试控制台
$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();
}
我找到了其他文档,其中展示了如何使用 result/response 进行更多调试:
var win = function (r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
$ionicLoading.hide();
}
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);
$ionicLoading.hide();
}
var ft = new FileTransfer();
ft.upload(fileURL, encodeURI("https://www.example.com/recieve_photos.php"), win, fail, options);
在那之后,我知道我得到了错误代码 3,这让我可以继续进行。