Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert content URL #14

Open
MBuchalik opened this issue Aug 30, 2016 · 4 comments
Open

Convert content URL #14

MBuchalik opened this issue Aug 30, 2016 · 4 comments

Comments

@MBuchalik
Copy link

When sharing to my application from a thirdparty app like google drive, I get files paths looking like this:
content://com.google.android.apps.docs.storage.legacy/something...

For some reason, using getRealPathFromContentUrl fires the success callback, but the variable passed to it is null. What can I do to open the file shared in this way? I tried using window.resolveLocalFileSystemURL on the content URL but that doesn't work (it returns a file error). I replaced "content://" with "file://" but this doesn't work either, the file cannot be opened as well. What could be the reason for that? Opening files from the device's photo gallery works fine! Tested on a Samsung Galaxy Alpha with Android 5.0.2. The app was created using PGB cli 6.3.0.

It would be reall nice if someone could point me in the right direction!

@alexislg2
Copy link

+1

@MBuchalik
Copy link
Author

MBuchalik commented Jan 10, 2017

I actually managed to solve it using resolveLocalFileSystemURL found in the official file plugin. I cannot tell if this works for all types of content URLs but it seems to be working fine on many 3rd party apps. Furthermore, I don't know why this didn't work while writing the post above. But when you only want to read the file (like I needed to do), using resolveLocalFileSystemURL works fine.

@sido420
Copy link

sido420 commented May 13, 2018

Hi @MBuchalik

So you used resolveLocalFileSystemURL to resolve the content:// URL received? Can you share relevant code how you resolved and read/access the file in your code please?

I'm stuck.

Thanks in advance.

@MBuchalik
Copy link
Author

@sido420 Hm I have done this more than a year ago so I can't remember every single step that had to be done. I am using the following function to generate a file object out of the content uri:

function my_function_that_should_be_able_to_convert_the_content_uri(url, success, error) {
	window.resolveLocalFileSystemURL(
		url,
		function (dirEntry) {
			if(!dirEntry.isFile) {
				error();
				return;
			}

			dirEntry.file(
				function(file) {
					success(file);
				},
				function() {
					error();
				}
			);
		},
		function() {
			// An error occured.
			error();
		}
	);
}

Then, you can build yourself a file reader and do whatever you like with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants