Skip to content

Commit

Permalink
[TIMOB-25849] Obtain mime-type from content provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed Mar 8, 2018
1 parent 5130c2a commit a514e73
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,7 @@ protected static KrollDict createDictForImage(String path)
{
String[] parts = { path };
TiBlob imageData;

// Workaround for TIMOB-19910. Image is in the Google Photos cloud and not on device.
if (path.startsWith("content://com.google.android.apps.photos.contentprovider")) {
ParcelFileDescriptor parcelFileDescriptor;
Expand All @@ -1125,14 +1126,14 @@ protected static KrollDict createDictForImage(String path)
parcelFileDescriptor.close();
imageData = TiBlob.blobFromImage(image);
} catch (FileNotFoundException e) {
imageData = createImageData(parts, MIME_IMAGE);
imageData = createImageData(parts, null);
} catch (IOException e) {
imageData = createImageData(parts, MIME_IMAGE);
imageData = createImageData(parts, null);
}
} else {
imageData = createImageData(parts, MIME_IMAGE);
imageData = createImageData(parts, null);
}
return createDictForImage(imageData, MIME_IMAGE);
return createDictForImage(imageData, null);
}

public static TiBlob createImageData(String[] parts, String mimeType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

import java.util.HashMap;

import android.net.Uri;
import android.webkit.MimeTypeMap;

import org.appcelerator.titanium.TiApplication;

public class TiMimeTypeHelper
{
public static final String MIME_TYPE_JAVASCRIPT = "text/javascript";
Expand Down Expand Up @@ -54,6 +57,14 @@ public static String getFileExtensionFromUrl(String url)

public static String getMimeType(String url, String defaultType)
{
// attempt to obtain mime-type from content provider
if (url.startsWith("content://")) {
final String mimeType = TiApplication.getInstance().getContentResolver().getType(Uri.parse(url));
if (mimeType != null) {
return mimeType;
}
}

String extension = "";
int pos = url.lastIndexOf('.');
if (pos > 0) {
Expand Down

0 comments on commit a514e73

Please sign in to comment.