Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: video upload issue through image picker #2204

Merged
merged 5 commits into from
Aug 3, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ const AttachmentVideo: React.FC<AttachmentVideoProps> = (props) => {
Alert.alert('Maximum number of files reached');
return files;
}
// We need a mime-type to upload a video file.
const mimeType = lookup(asset.filename) || 'multipart/form-data';
return [
...files,
{
duration: durationLabel,
id: asset.id,
mimeType,
name: asset.filename,
size: asset.fileSize,
type: 'video',
uri: asset.uri,
},
];
Expand Down Expand Up @@ -174,16 +176,6 @@ const AttachmentImage: React.FC<AttachmentImageProps> = (props) => {
);
};

const getFileType = (asset: Asset) => {
const { filename } = asset;
if (filename) {
const contentType = lookup(filename) || 'multipart/form-data';
return contentType.startsWith('image/') ? 'image' : 'video';
} else {
return asset.type === 'video' ? 'video' : 'image';
}
};

export const renderAttachmentPickerItem = ({ item }: { item: AttachmentPickerItemType }) => {
const {
asset,
Expand All @@ -196,9 +188,28 @@ export const renderAttachmentPickerItem = ({ item }: { item: AttachmentPickerIte
setSelectedImages,
} = item;

const fileType = getFileType(asset);
/**
* Native Android - Gives mime type(Eg: image/jpeg, video/mp4, etc.)
* Native iOS - Gives `image` or `video`
* Expo Android/iOS - Gives `photo` or `video`
**/
const isVideoType = asset.type.includes('video');

if (isVideoType) {
return (
<AttachmentVideo
asset={asset}
ImageOverlaySelectedComponent={ImageOverlaySelectedComponent}
maxNumberOfFiles={maxNumberOfFiles}
numberOfAttachmentPickerImageColumns={numberOfAttachmentPickerImageColumns}
numberOfUploads={numberOfUploads}
selected={selected}
setSelectedFiles={setSelectedFiles}
/>
);
}

return fileType === 'image' ? (
return (
<AttachmentImage
asset={asset}
ImageOverlaySelectedComponent={ImageOverlaySelectedComponent}
Expand All @@ -208,16 +219,6 @@ export const renderAttachmentPickerItem = ({ item }: { item: AttachmentPickerIte
selected={selected}
setSelectedImages={setSelectedImages}
/>
) : (
<AttachmentVideo
asset={asset}
ImageOverlaySelectedComponent={ImageOverlaySelectedComponent}
maxNumberOfFiles={maxNumberOfFiles}
numberOfAttachmentPickerImageColumns={numberOfAttachmentPickerImageColumns}
numberOfUploads={numberOfUploads}
selected={selected}
setSelectedFiles={setSelectedFiles}
/>
);
};

Expand Down
Loading