How to read file from iOS using FileReader?


#1

Hi All,
All day I’m trying to read an image that was captured by cordova camera, I did all the below tests and I get empty result, the thing that I don’t get even error, just nothing:

Step1: Capture photo

var options = {
    quality: 100,
    destinationType: Camera.DestinationType.FILE_URI,
    sourceType: Camera.PictureSourceType.CAMERA,
    encodingType: Camera.EncodingType.JPEG,
    cameraDirection: 1,
    saveToPhotoAlbum: true
};
$scope.capturePhoto = function () {
    // Take picture using device camera and retrieve image as base64-encoded string
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, options);
}  

Step 2: move image

  function onPhotoDataSuccess(imageData) {
        // Uncomment to view the base64-encoded image data
        console.log(imageData);
        movePic(imageData);
    } 

//Callback function when the file system uri has been resolved
function resolveOnSuccess(entry) {
var d = new Date();
var n = d.getTime();
//new file name
var newFileName = n + “.jpg”;
var myFolderApp = “tracker”;
$scope.tempFile = entry.fullPath;

        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSys) {
                //The folder is created if doesn't exist
                fileSys.root.getDirectory(myFolderApp,
                    {create: true, exclusive: false},
                    function (directory) {
                        entry.moveTo(directory, newFileName, successMove, resOnError);
                    },
                    resOnError);
            },
            resOnError);
    }  

Step 3: trying to read file with no success

var file = '/var/mobile/Containers/Data/Application/EC8630C8-80D7-45A5-968C-5E34930D396D/tmp/cdv_photo_002.jpg';
        var file2 = 'file:///var/mobile/Containers/Data/Application/EC8630C8-80D7-45A5-968C-5E34930D396D/tmp/cdv_photo_002.jpg';
        var file3 = '/tracker/1485605065847.jpg';
        var file4 = 'file:///tracker/1485605065847.jpg';
        var file5 = 'file:///var/mobile/Containers/Data/Application/6CF08171-8624-4977-8674-580AD7275704/Documents/tracker/1485635153691.jpg';
        var file6 = '/var/mobile/Containers/Data/Application/6CF08171-8624-4977-8674-580AD7275704/Documents/tracker/1485635153691.jpg';
        var reader = new FileReader();
        console.log(reader.readAsDataURL(file));
        console.log(reader.readAsDataURL(file2));
        console.log(reader.readAsDataURL(file3));
        console.log(reader.readAsDataURL(file4));
        console.log(reader.readAsDataURL(file5));
        console.log(reader.readAsDataURL(file6));
        console.log(reader.readAsText(file));
        console.log(reader.readAsText(file2));
        console.log(reader.readAsText(file3));
        console.log(reader.readAsText(file4));
        console.log(reader.readAsText(file5));
        console.log(reader.readAsText(file6));
        console.log(reader.readAsArrayBuffer(file));
        console.log(reader.readAsArrayBuffer(file2));
        console.log(reader.readAsArrayBuffer(file3));
        console.log(reader.readAsArrayBuffer(file4));
        console.log(reader.readAsArrayBuffer(file5));
        console.log(reader.readAsArrayBuffer(file6));
        console.log(reader.readAsBinaryString(file));
        console.log(reader.readAsBinaryString(file2));
        console.log(reader.readAsBinaryString(file3));
        console.log(reader.readAsBinaryString(file4));
        console.log(reader.readAsBinaryString(file5));
        console.log(reader.readAsBinaryString(file6));

any idea how to read the binary data, I want to upload it to S3?


#2

see this - it is in Ionic2 but the code should be able to work in Ionic1


#3

Hi! Finally could you solve this ?
Thanks !


#4

still no luck, I will back to work on this feature next week, I will update if I will have something.