I’m using https://github.com/apache/cordova-plugin-camera to take a photo and https://github.com/apache/cordova-plugin-file-transfer to upload it to a folder on my server. Works great, nothing special.
But for a few reasons I’m considering storing my Ionic app elements on my own server (pointing Xcode to the URL instead of the local address). In testing everything still works great except that I can’t get the photo preview to load in my template’s img ng-src like it normally does after snapping a photo.
At first I thought server configuration like CORS or something and tried things like this in htaccess without a change:
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
Then I thought perhaps something with $sce and for example tried things like this with the camera result:
$scope.trustSrc = function(src) {
return $sce.trustAsResourceUrl(src);
}
$scope.myPhoto = { src: FILE_URI };
and then:
<img ng-src="{{trustSrc(myPhoto.src)}}" style="width: 100%; height: auto; overflow: scroll;">
Of course works fine when I do a normal ionic build but if I run the very same with Ionic on the server I still get no image preview. Before my server tests I was just doing:
$scope.myPhoto = FILE_URI;
and
<img ng-src={{myPhoto}} style="width: 100%; height: auto; overflow: scroll;">
Again works great when everything is local but when that didn’t load the photo preview with Ionic living on the server I started to experiment.
Just to be clear, the photo is still being taken and I can still use my method for naming and uploading the picture without any issue, I just can’t see the preview of the image. The only issue is that the result from the camera doesn’t load in ng-src to preview the image if the Ionic resources are on the server instead of local, even though I can still do whatever else I want with the image.
Does anybody think they know why? I’m pretty new to Angular and Ionic so perhaps this one is obvious to someone who’s been in this realm for a while. I really need a new perspective! Anyone have thoughts?