I want to upload my image from my photo gallery in ios simulator to my amzazon s3 bucket. This code works fine on android but refuses to work on iOS and im not sure why
code to select photo from image gallery
$scope.choosePhoto = function(index) {
var options = {
destinationType : Camera.DestinationType.FILE_URL,
sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit : false,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
mediaType: Camera.MediaType.PICTURE,
correctOrientation: true
};
// 3
$cordovaCamera.getPicture(options).then(function(imageData) {
// 4
var imagetype;
onImageSuccess(imageData);
function onImageSuccess(fileURI) {
createFileEntry(fileURI);
}
function createFileEntry(fileURI) {
window.resolveLocalFileSystemURL(fileURI, copyFile, fail);
}
// 5
function copyFile(fileEntry) {
var name = fileEntry.fullPath.substr(fileEntry.fullPath.lastIndexOf('/') + 1);
var newName = (new Date()).getTime() + name;
halfthru(fileEntry, newName); //diff
getImageType(fileEntry); //diff
}
function getImageType(fileEntry) { //diff
var typeImage;
$scope.$evalAsync(function() {
fileEntry.file(function(file){
typeImage= file.type;
$scope.imagelist = typeImage;
imagetype = typeImage;
}, function(e){
});
})
}
function halfthru(fileEntry, newName) {
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(fileSystem2) {
fileEntry.copyTo(
fileSystem2,
newName,
onCopySuccess,
fail
);
}, fail);
}
// 6
function onCopySuccess(entry) {
$scope.activeSlide = index;
$scope.modal1.show();
$scope.$evalAsync($scope.images.push({file: entry.nativeURL, type: $scope.imagelist}));
imagesModalCount = $scope.images.length;
attachedImageCount = $scope.imagesAttached.length;
$scope.$on('$destroy', function() {
$scope.modal1.remove();
});
}
function fail(error) {
}
}, function(err) {
});
}
code to upload to amazon
$scope.uploadImage = function(imageURI, fileName) {
var deferred = $q.defer();
createCase.getAws().then(function(awsDetails) {
var policy = awsDetails.policy;
var signature = awsDetails.signature;
var key = awsDetails.key;
var datenow = awsDetails.datenow;
var s3URI = encodeURI("https://partners-mobile-app.s3.amazonaws.com/"),
awsKey = key,
policyBase64 = policy,
acl = "public-read";
var ft = new FileTransfer();
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileName;
options.mimeType = "image/jpeg";
options.chunkedMode = false;
options.headers = {
Connection: "close"
};
options.params = {
"key": fileName,
"AWSAccessKeyId": key,
"acl": acl,
"policy": policyBase64,
"signature": signature,
"Content-Type": "image/jpeg"
};
var f = ft.upload(imageURI, s3URI,
function (e) {
console.log("uploadimage: "+ imageURI)
console.log("uploads3uri: "+ s3URI)
console.log("im in upload now")
$scope.finalimagelist.push(s3URI+fileName);
if($scope.finalimagelist.length === $scope.images.length){
console.log("OK SER GO")
deferred.resolve($scope.finalimagelist);
}
},
function (e) {
deferred.reject(e);
},
options);
}
SO basically, i choose the image from image gallery and then upload to amazon everythg looks good but it just doesnt upload the image and i dont know why.
I am using AngularJS and the plugin cordova-plugin-file-transfer
my info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>