How to access local files in cordova?


#1

The issues is discussed in more detail here: https://github.com/meteor/meteor/issues/3799

I am saving images in cordova and would like to access same via an <img tag, which results in the following error

Not allowed to load local resource: file:///var/mobile/Containers/Data/Application/FFEDAE34-F254-45B8-A1D0-71B63C270D39/Library/NoCloud/myphoto.jpeg

My question to the community is. What is the best approach/workaround to deal with that? Nathan published a demo showing an approach using a web server to serve up files written to the file system with the file transfer plugin: https://github.com/nate-strauser/meteor-offline-mobile-files-demo.

However, I am not sure what the security implications of such an approach are? Are there alternatives or is this seen as a best practice approach for the time being?


Meteor approach to Cordova-App with lots of photos
#2

Anyone? Isn’t that a standard use case in most mobile apps?


#3

I am also looking for an answer to this question. I have similar use case and concerns.

Should this not be a standard use case to support ?


#4

Also here. I need to access local files, I’m currently watching few pages with that specific issue, maybe someone will provide a decent solution

Read this tread:



#5

Bump.

@miriam7: Totally agree, this is a standard use case. Ran into the same problem.


#6

Any updates on the subject?
I don’t understand why such a basic task is so hard to achieve. Now the only solution that might work is to base64 the images with the cordova File plugin, but it’s a no no when it comes to multiple big images.


#7

Good news, local file access is supported in Meteor 1.3: https://github.com/meteor/meteor/issues/6266


#8

I’m facing the same problem in Meteor 1.3.2


#9

And in Meteor 1.4.2.6


#10

and in 1.4.3

Im trying WebAppLocalServer.localFileSystemUrl but nothing


#11

Quite disappointing when you are looking into this again and you find yourself asking for a solution a while ago with no answer between


#12

I had this problem last night and was redirected to this thread. Although the solution I found was incomplete. I was able to make it work after a lot of searching and trial and error.

Here is how I solved this:

  1. Install this plugin: cordova-plugin-filepath
  2. Here is how I use the plugin together with provided tool by Meteor
        if (imageLocalPath.startsWith('content://')) {
            FilePath.resolveNativePath(
                imageLocalPath,
                filePath => {
                    useLocalFile(WebAppLocalServer.localFileSystemUrl(filePath));
                },
                error => {}
            );
        } else {
            useLocalFile(WebAppLocalServer.localFileSystemUrl(imageLocalPath));
        }