Skip to content

Commit

Permalink
Merge pull request #9906 from garymathews/TIMOB-25409
Browse files Browse the repository at this point in the history
[TIMOB-25409] Android: Resolve remote content uris
  • Loading branch information
lokeshchdhry committed Mar 21, 2018
2 parents a81b170 + 43ea7dc commit 0d80c4f
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
package org.appcelerator.titanium.io;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.util.TiFileHelper;

import android.content.ContentUris;
import android.database.Cursor;
Expand All @@ -22,6 +25,8 @@

public class TitaniumBlob extends TiBaseFile
{
private static final String TAG = "TitaniumBlob";

protected String url;
protected String name;
protected String path;
Expand Down Expand Up @@ -86,6 +91,19 @@ protected void init()
name = c.getString(0);
path = c.getString(1);
}

// must be a remote file, save locally as a temp file
// TODO: we should refactor our content resolving implementation
if (path == null) {
try {
InputStream inputStream =
TiApplication.getInstance().getContentResolver().openInputStream(Uri.parse(url));
File tempFile = TiFileHelper.getInstance().getTempFileFromInputStream(inputStream, name, true);
path = tempFile.getPath();
} catch (FileNotFoundException e) {
Log.e(TAG, "could not find " + url);
}
}
} finally {
if (c != null) {
c.close();
Expand Down

0 comments on commit 0d80c4f

Please sign in to comment.