Iam using cordova 3.4. When i capture an image and set it,its working fine but when I try to access on image from gallery I get the url
content://com.android.providers.media.documents/document/image%4A463
and I get image load error in my image tag.I know this is a know bug going around and I have refered stack questions such as Unable to load image when selected from the gallery on Android 4.4 (KitKat) using PhoneGap Camera Plugin
I cannot use the rough work around mentioned where URI is set manually like content://media/external/images/media/ because we focus devices with internal built in storage such as Moto
Also can you please confirm that this issue has been fixed in cordova 3.5.Because I require permission from my officials for download and I must make sure it is achievable .Can somebody please help
UPDATE:
app.directive('upload', function() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
elm.on('click', function() {
navigator.camera.getPicture(
function(imageURI) {
scope.$apply(function() {
alert(imageURI);
ctrl.$setViewValue(imageURI);
});
window.resolveLocalFileSystemURI(imageURI, function(fileEntry) {
// ctrl.$setViewValue(imageURI);
alert("inside local file" + imageURI);
alert("Inside local file system");
fileEntry.file(function(fileObj) {
alert("hai");
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileObj.name;
options.mimeType = fileObj.type;
var ft = new FileTransfer();
// var url = fileUploadUrl;
// ft.upload(imageUri, encodeURI(url), success, failure, options);
});
});
},
function(err) {
ctrl.$setValidity('error', false);
}, {quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY
}
);
});
}
};
});
My HTML:
<img
ng-src="{{onepic}}"
width="250"
height="390"
alt="error"/>
I set value for onepic in my controller inside watch function.So when directive returns a URI it will be automatically set in onepic.Please specify any alternative solution or if Iam doing anything wrong ,Iam new to angularjs
see this answer:
Whenever some
uri
is passed into<img src="uri" />
it's implicitly decoded frominto
However, after returning from
Intent.ACTION_OPEN_DOCUMENT
orIntent.ACTION_GET_CONTENT
Android provides you with the read permission for (1), not (2). In this caseWebView
will expectantly log an error:or
Code snippet
All you need to resolve the issue is
in your Java code before passing
uri
into HTML/JS to ensure that (1) will be actually loaded.I've tested that on 4.4.2, 4.4.4 and 5.0. The funny part is that Android 4.4.2 decodes the
uri
internally twice.Try this..
In Camera Plugin there is one
FileHelper.java
File, Replace the plugingetRealPath
with my this my method.For more details you can follow this -> https://issues.apache.org/jira/browse/CB-5398
FileHelper.java
In
CameraLauncher.java
Class therer is one methodprocessResultFromGallery
Find this code:
And replace with this: