我在Ionic中使用一些cordova插件(FileTransfer,Camera,File等)。
在视图效果很好的时候,我可以显示图像(相机和图库)但是在尝试上传时我得到一个FileTransfer错误代码= 1,这意味着找不到文件。所以当我检查我的app目录(cordova.file.dataDirectory和cordova.file.cacheDirectory)是空的时。
摄像头代码:
$scope.takePhoto = function(){
var optionsCamera = {
quality: 100,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
saveToPhotoAlbum: false,
correctOrientation: true
};
$cordovaCamera.getPicture(optionsCamera)
.then(function(imageData){
console.log(imageData);
var currentName = imageData.replace(/^.*[\\\/]/, '');
var namePath = imageData.substr(0, imageData.lastIndexOf('/') + 1);
console.log(currentName);
console.log(namePath);
//move from cache to files
$cordovaFile.moveFile(namePath, currentName, cordova.file.dataDirectory, 't_s'+currentName)
.then(function(successMove){
console.log(successMove);
$scope.imagenes.push('t_s'+currentName);
console.log($scope.imagenes);
}, function(errorMove){
console.log(errorMove);
});
}, function(errorCamera){
console.log(errorCamera);
})}
上传代码:
$scope.sendData = function() {
var server = Config.serverUrl() + '/product_image_upload/';
console.log($scope.imagenes);
//first image in array
var targetPath = $scope.imagenes[0];
var filename = ($scope.imagenes[0]).replace(/^.*[\\\/]/, '');
console.log(targetPath);
console.log(filename);
var options = {
httpMethod: 'POST',
fileKey: 'file',
filename: filename,
chunkedMode: false,
mimeType: 'multipart/form-data'
};
var params = {
'fileName' : filename,
};
//JWT token
var headers = {
'Authorization': $rootScope.token
};
options.headers = headers;
options.params = params;
console.log(options);
$cordovaFileTransfer.upload(server, targetPath, options).then(
function(result) {
// Success!
console.log('upload ok');
console.log(result);
}, function(err) {
// Error
console.log(err);
}, function(progress) {
// constant progress updates
console.log(progress);
$scope.progress = progress;
})}
我想知道,文件在哪里?