Block video upload (or even selection) on Mobile app #1711
-
Is there a way to block video upload (or event earlier video selection) on Mobile? |
Beta Was this translation helpful? Give feedback.
Answered by
vishalnarkhede
Sep 7, 2022
Replies: 1 comment 3 replies
-
@neopit To disallow video upload, please take a look at How to block certain file extensions from uploads. But to disallow video selection in media picker, you will need to override native handler, specifically getPhotos handler.
import { registerNativeHandlers } from 'stream-chat-react-native';
import { Image, PermissionsAndroid, Platform } from 'react-native';
import { CameraRoll } from '@react-native-camera-roll/camera-roll';
registerNativeHandlers({
getPhotos: async ({ after, first }) => {
try {
if (Platform.OS === 'android') {
const readExternalStoragePermissionAndroid =
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE;
const hasPermission = await PermissionsAndroid.check(readExternalStoragePermissionAndroid);
if (!hasPermission) {
const granted = await PermissionsAndroid.request(readExternalStoragePermissionAndroid, {
buttonNegative: 'Deny',
buttonNeutral: 'Ask Me Later',
buttonPositive: 'Allow',
message: 'Permissions are required to access and share photos.',
title: 'Photos Access',
});
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
throw new Error('getPhotos Error');
}
}
}
const results = await CameraRoll.getPhotos({
after,
assetType: 'Photos', // <-- THIS IS THE ONLY CHANGE HERE.
first,
include: ['fileSize', 'filename', 'imageSize', 'playableDuration'],
});
const assets = results.edges.map((edge) => ({
...edge.node.image,
source: 'picker',
}));
const hasNextPage = results.page_info.has_next_page;
const endCursor = results.page_info.end_cursor;
return { assets, endCursor, hasNextPage };
} catch (_error) {
throw new Error('getPhotos Error');
}
},
}); |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
vanGalilea
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@neopit To disallow video upload, please take a look at How to block certain file extensions from uploads.
But to disallow video selection in media picker, you will need to override native handler, specifically getPhotos handler.