Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhoneGap resolveLocalFileSystemURL Issue (Error 5)

I am using PhoneGap Build to build an iOS application and using weinre to debug. So far so good.

I am trying to use the media-capture and file APIs to capture a video and get its base64 representation. I can get the video recorder to open, take a video, and return. The problem is I can not get resolveLocalFileSystemURL to open the given path. Every time it returns with an error code of 5 to which I can not seem to find a single answer as to what that means. This is running on a real device so it is not a problem with the emulator.

I have checked every post I could find via Google and Stack Overflow I have read blog posts and the comments within. Have been scratching my head for days on this one. Everyone who proposed an answer was either using Xcode-- as opposed to Build-- or the answer simply did not work for me. This is such a simple thing to have to do, I can not figure out where the problem could be...

Below is my code. Below that is the console output.

elements["media_video"].onclick = function(event) {
    navigator.device.capture.captureVideo(
        function(files) {
            for ( var i = 0 ; i < files.length ; ++i ) {
                var file = files[i];
                var name = file.name;
                var path = file.fullPath;
                var type = file.type;
                var lastModifiedDate = file.lastModifiedDate;
                var size = file.size;
                console.log(0, name, path, type, lastModifiedDate, size);
                var reader = new FileReader();
                reader.onloadend = function(event) {
                    console.log(3, event.target.result);
                };
                window.resolveLocalFileSystemURL(
                    path,
                    function(entry) {
                        console.log(1, entry.name);
                        reader.readAsDataURL(entry);
                        // send base64 data to server
                    },
                    function(error) {
                        console.log(2, error.code);
                    }
                );
            }
        },
        function(error) {},
        {
            limit:  1
        }
    );
};

0 "capturedvideo.MOV" "/private/var/mobile/Applications/[application uuid]/tmp/capture/capturedvideo.MOV" "video/quicktime" 1409866447000 205788

2 5

Edit 1 I do not have a Mac on which to use Xcode which is why I choose a cloud-based service.

Edit 2 Testing on iOS v7.1.2.

like image 254
Nicholas J Ingrassellino Avatar asked Dec 26 '22 04:12

Nicholas J Ingrassellino


1 Answers

Take /private off the initial path (on older iOS versions [<7], you need to take off the /localhost portion of the path).

For some reason iOS thinks you shouldn't be able to have access to any directory starting with private even if the full path eventually lands within your sandbox. Frustrating to debug, to say the least, but it is an easy fix once you know what to look for.


Edited 8/5/2014 6:06:


I just now noticed you also aren't supplying a URL scheme -- you need to have file:// prepended to your path, otherwise you get this particular error. Your final path should look like this prior to calling resolveLocalFileSystemURL:

file:///var/mobile/Applications/[application uuid]/tmp/capture/capturedvideo.MOV
like image 182
Kerri Shotts Avatar answered Jan 09 '23 12:01

Kerri Shotts