mirror of
https://github.com/apache/cordova-android.git
synced 2025-04-22 16:50:45 +08:00
CB-2093: NullPointerException when attaching image from Gallery that contains spaces in the path
Guarding against a null string being passed into FileUtils.getMimeType()
This commit is contained in:
parent
c130396d4e
commit
a1cfe87f1e
@ -1019,15 +1019,19 @@ public class FileUtils extends CordovaPlugin {
|
|||||||
* @return a mime type
|
* @return a mime type
|
||||||
*/
|
*/
|
||||||
public static String getMimeType(String filename) {
|
public static String getMimeType(String filename) {
|
||||||
// Stupid bug in getFileExtensionFromUrl when the file name has a space
|
if (filename != null) {
|
||||||
// So we need to replace the space with a url encoded %20
|
// Stupid bug in getFileExtensionFromUrl when the file name has a space
|
||||||
String url = filename.replace(" ", "%20");
|
// So we need to replace the space with a url encoded %20
|
||||||
MimeTypeMap map = MimeTypeMap.getSingleton();
|
String url = filename.replace(" ", "%20");
|
||||||
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
|
MimeTypeMap map = MimeTypeMap.getSingleton();
|
||||||
if (extension.toLowerCase().equals("3ga")) {
|
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
|
||||||
return "audio/3gpp";
|
if (extension.toLowerCase().equals("3ga")) {
|
||||||
|
return "audio/3gpp";
|
||||||
|
} else {
|
||||||
|
return map.getMimeTypeFromExtension(extension);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return map.getMimeTypeFromExtension(extension);
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user