Multiple Image selection from gallery using Cordova Camera plugin - ionic-framework

I am making an application based on ionic-1 where I need to take access camera as well as gallery. I used Cordova Camera plugins. It is working properly. Using this plugin we can access not only our device gallery but also our drive, documents etc. But main problem is, I cant select multiple image from gallery. I need to select it one by one.
How may I solve this issue..? I do not want to use cordova image picker plugins.

You can solve this issue by using cordova-imagePicker plugin. you can access it from github.
The plugin creates the object window.imagePicker with the method
getPictures(success, fail, options).
with this plugin you can select multiple photos
window.imagePicker.getPictures(
function(results) {
for (var i = 0; i < results.length; i++) {
console.log('Image URI: ' + results[i]);
}
}, function (error) {
console.log('Error: ' + error);
} ); Example - Get at most 10 images scaled to width of 800:
window.imagePicker.getPictures(
function(results) {
for (var i = 0; i < results.length; i++) {
console.log('Image URI: ' + results[i]);
}
}, function (error) {
console.log('Error: ' + error);
}, {
maximumImagesCount: 10,
width: 800
} );

Related

ngCordova filetransfer not getting path for picture from camera

I have a mobile app that I've created where I want users to be able to take a picture and save it to a server.
I've followed the tutorials, but for some reason the file transfer is not working.
Here is my code:
$cordovaCamera.getPicture(options).then(function( imageData ) {
// self.imgURI = "data:image/jpeg;base64," + imageData;
var server = API_ENDPOINT + '/fileuploads'
var filePath = "data:image/jpeg; base64," + imageData;
document.addEventListener('deviceready', function() {
$cordovaFileTransfer.upload(server, filePath)
.then(function(result) {
// Success!
}, function(err) {
// Error
}, function(progress) {
// constant progress updates
});
}, false);
}
The Cordova plugin for the camera works great, just an issue with saving the file.
If you are specifically looking to get File Url of the image returned from the Camera plugin, following should be the options for the camera plugin:
var options = {
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
};
If you are facing any other specific issue, please mention.
Hope this helps.

ionic 1.x : crop image

I have two buttons, the first one for browse image from gallery and the second one for taking photo. I'm using cordova camera plugin for two cases.
After choosing an image, I want to crop it before to send to server using cordova file transfer plugin. I've tried to use several plugins such as jr-crop, angular-image-crop, ngImgCrop. The problem is that plugins returns a base64 image, but I want to get the image url (not dataUrl). Any help please !
My solution (#egycode) :
$scope.image_gallery = function() {
var options = {
quality: 100,
correctOrientation: true,
sourceType: 0
};
$cordovaCamera.getPicture(options).then(function(data) {
console.log(data);
$scope.crop(data);
console.log('camera data image_gallery: ' + angular.toJson(data));
}, function(error) {
console.log('camera error image_gallery: ' + angular.toJson(error));
});
}
$scope.crop = function(url) {
$jrCrop.crop({
url: url,
width: 261,
height: 362
}).then(function(canvas) {
console.log(canvas);
var image = canvas.toDataURL();
//var image is the result, you can show it using : $scope.pictureUrl = image;
}, function() {
// User canceled or couldn't load image.
});
}

Ionic Framework display dynamic value inside $ionicLoading

How can I display a dynamic value inside of ionicLoading?
Here is my code to show $ionicLoading, the idea here is to display download progress:
$rootScope.updateProgress = 0;
$ionicLoading.show({
template: 'Updating...' + $rootScope.updateProgress
});
And later in my code I update $rootScope.updateProgress's value:
var iPecent = Math.round(downloadProgress.receivedBytes / downloadProgress.totalBytes * 100);
$rootScope.$apply(function () {
$rootScope.updateProgress = iPecent;
});
However, $rootScope.updateProgress's value is not reflected when $ionicLoading is displayed on the screen - just shows initial value of 0. If I log out $rootScope.updateProgress's value it is reflecting current download progress.
Let me use cordova-plugin-file-transfer as an example:
$ionicLoading.show({
template: 'downloading...'
});
$cordovaFileTransfer.download(source, filePath, options, trustAllHosts).then(function (result) {
console.log('download successfully!');
$ionicLoading.hide();
}, function (err) {
alert('download failed!' + err);
}, function (progress) {
var downloadProgress = (progress.loaded / progress.total) * 100;
$ionicLoading.show({
template: "Downloaded:" + Math.floor(downloadProgress) + "%"
});
if (downloadProgress >= 100) {
$ionicLoading.hide();
}
});
I believe this was requested and added here https://github.com/driftyco/ionic/issues/699.
I haven't tested it, but based on the statement:
Use $ionicLoading.show() while the loader is open with new content,
and it will update the content.
If you call .show() subsequent to a $ionicLoading already showing, it should update the content.. If this feature is in fact now part of Ionic, and you put in some sort of loop and delay routine, you should be able to achieve what you're after.
Hi i am using show percentage of image uploading like 19%...
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
$ionicLoading.show({
template: 'Uploading Start....' + parseInt(100.0 * evt.loaded /evt.total) + '%',
});
where evt is callback of progress method.

Image uploaded from Mobile phone to Angular is sideways or upside down

I am able to upload images from my desktop to an Angular based Web Application overlayed on SharePoint without issue, but if I upload from a Mobile phone, such as an iPhone, using the take "Take Photo or Video" or "Photo Library" function, it causes the image to be sideways when taken in portrait or upside down when taken in landscape. Here is my current upload function. Any clues/have others had the same issues uploading to Mobile Web Applications from iPhones/Mobile Phones to a SharePoint library?
Here is my upload function:
// Upload of images
$scope.upload = function () {
//console.log($scope.files);
if (document.getElementById("file").files.length === 0) {
alert('No file was selected');
return;
}
var parts = document.getElementById("file").value.split("\\");
var uploadedfilename = parts[parts.length - 1];
var basefilename = uploadedfilename.split(".")[0];
var fileextension = uploadedfilename.split(".")[1];
var currentdate = new Date();
var formatteddate = $filter('date')(new Date(currentdate), 'MMddyy-hmmssa');
var filename = basefilename + formatteddate + '.' + fileextension;
var file = document.getElementById("file").files[0];
uploadFileSync("/sites/asite", "Images", filename, file);
}
//Upload file synchronously
function uploadFileSync(spWebUrl, library, filename, file)
{
console.log(filename);
var reader = new FileReader();
reader.onloadend = function(evt)
{
if (evt.target.readyState == FileReader.DONE)
{
var buffer = evt.target.result;
var completeUrl = spWebUrl
+ "/_api/web/lists/getByTitle('"+ library +"')"
+ "/RootFolder/Files/add(url='"+ filename +"',overwrite='true')?"
+ "#TargetLibrary='"+library+"'&#TargetFileName='"+ filename +"'";
$.ajax({
url: completeUrl,
type: "POST",
data: buffer,
async: false,
processData: false,
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-length": buffer.byteLength
},
complete: function (data) {
console.log(data);
},
error: function (err) {
alert('failed');
}
});
}
};
reader.readAsArrayBuffer(file);
}
The output of these is just pushed into an array for use in an Angular UI Carousel:
// Control of Image Carousel
$scope.myInterval = 0;
// Population of carousel
$scope.slides = [];
appImages.query({
$select: 'FileLeafRef,ID,Created,Title,UniqueId',
$filter: 'ReportId eq ' + $routeParams.Id + ' and DisplayinReport eq 1',
}, function (getimageinfo) {
// Data is within an object of "value"
var image = getimageinfo.value;
// Iterate over item and get ID
angular.forEach(image, function (imagevalue, imagekey) {
$scope.slides.push({
image: '/sites/asite/Images/' + imagevalue.FileLeafRef,
});
});
});
The image carousel is on page as follows:
<div style="height: 305px; width: 300px">
<carousel interval="myInterval">
<slide ng-repeat="slide in slides" active="slide.active">
<img ng-src="{{slide.image}}" style="margin:auto;height:300px">
<div class="carousel-caption">
<h4>Slide {{$index}}</h4>
<p>{{slide.text}}</p>
</div>
</slide>
</carousel>
</div>
IMPORTANT: The images are sideways and upside down upon upload to the SharePoint library, so irrespective of outputting them, they seem to be misoriented when they hit the destination library I am using as a source to display on page.
How do I upload the images so SharePoint respects the EXIF data/orientation?
It may be related to EXIF. See JS Client-Side Exif Orientation: Rotate and Mirror JPEG Images
If you want a better answer, we will need the code which show the image, and the code server side.
UPDATE : I'm not an expert at all on SharePoint, but you can found a lot about it in the SharePoint Stack Exchange. For example, https://sharepoint.stackexchange.com/questions/131552/sharepoint-rotating-pictures-in-library, should do the trick.
To sum up a little : in your case, their could be a lot of cases to study. So, I recommended you auto-correct the exif, and then permit to your user to correct it if the auto-correct was wrong. Their is a lot of tools to do that. If you want to do it server-side, look at the link above, and if you want to do it on the client side, you could use JS-Load-Image for example.

Display Facebook Album Cover Image

I'm trying to show the cover photos of a Facebook user's albums, but I am not having any luck.
What I have so far is this:
FB.api('/me/albums', function(response) {
for(var i = 0; i < response.data.length; i++)
{
if(response.data[i].cover_photo != undefined)
{
var alb = $('<div class="album" id="album-' + response.data[i].cover_photo + '"></div>').appendTo(view_scroll);
alb.css('background', 'url(https://graph.facebook.com/' + response.data[i].cover_photo + '/picture)');
}
}
});
All I am getting is a question mark image. Any suggestions on how get the actual cover image into the background of the div?
Found it... Needed to add the access token to the end of the url:
background-image: url(https://graph.facebook.com/' + response.data[i].cover_photo + '/picture?access_token=' + [ACCESSTOKEN]
Hi i had the same problem, and i already got the cover_photo from every album of the user. Im using javascript sdk. After checking the login status, just call the function albumes():
function albumes() {
FB.api('/me/albums?fields=name,link,cover_photo,id',
function(response) {
for(var c = 0 ; c < response.data.length ; c++) {
coverPhoto(response.data[c].cover_photo, response.data[c].name);
}
}
);
}
function coverPhoto(id, nombre){
FB.api('/'+id+'?fields=picture',
function(responseIn) {
$('#javascriptData').append(
"<br>"+ nombre +"<img src='"+ responseIn['picture'] +"'>");
}
);
}