【发布时间】:2017-07-07 23:32:47
【问题描述】:
我正在尝试将图像存储到 Firebase 存储,但我在使用 Android 设备时遇到了一些困难。它在 iOS 上运行良好。
问题是当我从库中选择图片时出现以下错误:
FileError {code: 1, message: "NOT_FOUND_ERR"}
这是我的代码:
$scope.fireStoreAvatar = function($sourceType) {
if ($sourceType == 1) {
var options = {
quality: 100,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 1024,
targetHeight: 1024,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation:true
};
} else {
var options = {
quality: 100,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 1024,
targetHeight: 1024,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation:true
};
}
// Get image from camera or library
$cordovaCamera.getPicture(options).then(function(imageData) {
var fileName = "";
var path1 = "";
var path2 = "";
if ($ionicPlatform.is("android")) {
$log.debug('android:');
var path1 = cordova.file.cacheDirectory;
var fileName = imageData.replace(/^.*[\\\/]/,'');
var path2 = imageData.replace(fileName,'');
} else {
$log.debug('ios:');
path = cordova.file.tempDirectory;
var fileName = imageData.replace(/^.*[\\\/]/,'');
}
$log.debug('$cordovaCamera.getPicture => imageData: ' + imageData);
$log.debug('cordova.file.cacheDirectory => path1: ' + path1);
$log.debug('imageData.replace(fileName,"") => path2: ' + path2);
$log.debug(' fileName: ' + fileName);
$cordovaFile.checkFile(path1, fileName)
.then(function (data) {
$log.info('checkFile(path1, fileName) => OK');
$log.info(data);
}, function (error) {
$log.warn('checkFile(path1, fileName) => NOT OK');
$log.error(error);
});
$cordovaFile.checkFile(path2, fileName)
.then(function (data) {
$log.info('checkFile(path2, fileName) => OK');
$log.info(data);
}, function (error) {
$log.warn('checkFile(path2, fileName) => NOT OK');
$log.error(error);
});
$cordovaFile.readAsArrayBuffer(path1, fileName)
.then(function (data) {
$log.info('readAsArrayBuffer(path1, fileName) => OK');
$log.info(data);
// success
}, function (error) {
// error
$log.warn('readAsArrayBuffer(path1, fileName) => NOT OK');
$log.error(error);
});
$cordovaFile.readAsArrayBuffer(path2, fileName)
.then(function (data) {
$log.info('readAsArrayBuffer(path2, fileName) => OK');
$log.info(data);
// success
}, function (error) {
// error
$log.warn('readAsArrayBuffer(path2, fileName) => NOT OK');
$log.error(error);
});
}, function(err) {
// error
$log.error("Upload error: " + err);
});
}
我尝试了另一条路径 (path2),如果我使用设备相机拍照,则可以使用,但如果我从图库中选择图片,则无法使用。
从设备库中选择图片:
用设备相机拍照:
嗯,您可以观察到使用路径 2 和设备摄像头,$cordovaFile.readAsArrayBuffer 工作正常。
也许有人可以给我一些建议。 谢谢!
--
我试图按照 youtube 上的 Aaron Saunders 教程制作这个:
【问题讨论】:
-
你发现这个问题了吗?
标签: angularjs firebase ionic-framework ngcordova