I’m trying to save an image file to the photo gallery on iOS and Android. I’d be happy enough if I could provoke a prompt, such as when you tap and hold an image in Safari on iOS.
Is there a pure javascript way of doing this, or will I have to use a plugin?
This is perhaps more a Cordova question than an Ionic question, but I was hoping to find an “Ionic-y” solution. Something I could invoke from within a controller, for instance.
The camera plugin with ngCordova doesn’t support separate storage of images, does it? To clarify, I don’t want to take an image, but rather store an image downloaded from some web source to the camera roll / photo gallery.
As far as I can tell, there’s no specific plugin included in ngCordova that does this. I’ll go have a look on PlugReg.
Any updates?
The title makes it clear that we want to save an image (maybe downloaded from server and display in In-App-Browser by Cordova) into the ‘Gallery’
I ended up using the [Canvas2ImagePlugin][1], which appeared to be the only reliable way to save to the gallery on both Android and iOS at the time I wrote the original forum post.
This does have the advantage that you have to stick the image into a canvas first, but since I needed to display a preview of the image as well as perform a resize-to-fill, I did it all together with canvas.
[1]: https://github.com/devgeeks/Canvas2ImagePlugin
It does solve that problem as it doesn’t require any user interaction and doesn’t leave the app. This is the same way that UIImageWriteToSavedPhotosAlbum() works on iOS.
Having said all that. It would be great to have an ngCordova interface to something that could do all this without requiring the developer to manually create a canvas to resize their image, etc. Can’t promise anything, but I’ll look into it.
But it isn’t saving to the photo gallery. I think i might be using the wrong file paths and sending the location rather than the image data. Does anybody have any handy hints?
here is the solution to save image from URL using cordova file transfer.
var exampleApp=angular.module(‘starter’, [‘ionic’])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
});
exampleApp.controller(“FileController”, function($scope, $ionicLoading) {
$scope.url=“http://papers.com.pk/xads/2015/8-10/Express/1103007127-1.jpg”;
var filename = $scope.url.split("/").pop();
alert(filename);
$scope.download = function() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
fs.root.getDirectory(
“papers”,
{
It will create folder in your internal storage with the folder name ‘Papers’ . But you can choose any name for your folder
fs.root.getDirectory(
“papers”,
but pictures will not show in gallery because of the media scanner problem in android. In android we have to start media scanner manually through coding or you can install scan media app form play store . But i am working on this problem. I will update when i found the solution.
i found the solution how to add downloaded images to gallery. you have to add one function in FileTransfer.java file. i uploaded a image just make changes in this portion of your FileTransfer.java file.