Hello I’m having some troubles with Android uploading photos from the gallery to my server, the code works in iOS (Camera & Library) but in Android only the Camera works fine, I can’t upload a photo from the Librery!
Am I doing something wrong?
$scope.newObjectPhotoLibrary = function(relationIndex)
{
if (!isMaxNumbOfObjects())
{
var options = {
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
quality: 50,
allowEdit: true,
targetWidth: 350,
targetHeight: 350,
maximumImagesCount: 1
};
$cordovaCamera.getPicture(options).then(function(imageData) {
var name = imageData.substr(imageData.lastIndexOf('/') + 1);
var canonicalName = $rootScope.replaceDots(name);
var object = {value: canonicalName, path: imageData};
}, function(err) {
$ionicPopup.alert({
title: 'Error',
content: 'There was an error loading the image'
});
});
}
}
var options = {
fileKey: object.value,
fileName: object.path.substr(object.path.lastIndexOf('/') + 1),
chunkedMode: false,
};
$cordovaFileTransfer.upload(url, object.path, options)
.then(function(result) {
deferred.resolve(result);
}, function(err) {
// console.log(JSON.stringify(err));
deferred.reject(err);
}, function (progress) {
});
@Teravito I didnt understand your issue to start with. Sounded like you were having trouble uploading the image to the server, but I see it works in iOS, just the gallery is not working in android.
I would set the allowEdit to false. Android has an issue with this setting.
allowEdit is unpredictable on Android and it should not be used! The Android implementation of this plugin tries to find and use an application on the user’s device to do image cropping. The plugin has no control over what application the user selects to perform the image cropping and it is very possible that the user could choose an incompatible option and cause the plugin to fail. This sometimes works because most devices come with an application that handles cropping in a way that is compatible with this plugin (Google Plus Photos), but it is unwise to rely on that being the case. If image editing is essential to your application, consider seeking a third party library or plugin that provides its own image editing utility for a more robust solution.
Thanks Rcecy for the fast reply! Sorry about the messy code, I thought It would be correctly indented, it was my first post!
On the backend I’m running Symfony 3.0. As you said, my problem is that my code works on iOS but not in Android. I think that the cameraCapture is working fine, but the FileTransfer is unable to access the file for the upload when the image comes from the gallery, has been edited by a editor in Android.
I’m aware that some Androids won’t support editing, I tried to edit the image with a third party editor in the past as you said, but then I don’t know how to save it as a .jpg again.
I think I need to edit the image because I need square pictures, so if I don’t allow edit the image is deformed.
Any clue on how to convert base64 to jpg again? Either on the app or on the server.
var image = new Image();
image.src = 'data:image/png;base64,iVBORw0K.......';
Why not crop the image on the server? I have an app where the user uploads the original image and I create thumbnails using a php script. I am at home right now but have a few php image cropping scripts I can post tomorrow.
If I crop the image using php then I can’t control which part of the image I want to crop, or the zoom. That’s why the user should be able to do this in the app.