-
-
Notifications
You must be signed in to change notification settings - Fork 72
No reliable way to determine selected media's type #318
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
Comments
Any idea anyone? |
private resolveMediaType(path: string): string | CustomError {
if (!path) {
return new CustomError(
this.translateService.instant('services.noFileProvided')
);
}
try {
if (isAndroid) {
const cr = Application.android.context.getContentResolver();
const file = new java.io.File(path);
const sdkVersionInt = parseInt(Device.sdkVersion, 10);
const pkgName = Utils.ad.getApplication().getPackageName();
let mediaUri: string;
if (sdkVersionInt >= 21) {
const ContentNamespace =
global.androidx && global.androidx.appcompat
? androidx.core.content
: android.support.v4.content;
mediaUri = ContentNamespace.FileProvider.getUriForFile(
Application.android.foregroundActivity, // or app.android.currentContext ??
`${pkgName}.provider`,
file
);
} else {
mediaUri = android.net.Uri.fromFile(file);
}
return cr.getType(mediaUri);
} else if (isIOS) {
const mediaType = (path as any).mediaType;
switch (mediaType) {
case PHAssetMediaType.Image:
return 'image/*';
case PHAssetMediaType.Video:
return 'video/*';
}
return null;
}
} catch (e) {
console.log(e);
if (typeof path !== 'string') {
return new CustomError(
this.translateService.instant('services.unableToResolveMediaType')
);
}
const possibleImageFormats = ['.jpg', '.jpeg', '.png'];
return possibleImageFormats.some(format => path.endsWith(format))
? 'image/*'
: new CustomError(
this.translateService.instant('services.unableToResolveMediaType')
);
}
}
@pandabuilt I use this as a workaround, |
@nikoTM Can I see your imports? Or how do you get global.androidx, java and PHAssetMediaType |
@pandabuilt |
in 2.0.0, it will now return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Both videos and images are returned as
ImageAsset
, how can we reliably determinemediaType
from there?The text was updated successfully, but these errors were encountered: