react-native-share / react-native-share

Social share, sending simple data to other apps.

Home Page:https://react-native-share.github.io/react-native-share

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cant send video to whatsapp

Rickkorsten opened this issue · comments

Hello there,

on IOS (i did not test android) if i want to send a video (mp4) with whatsapp it does not send the video it only sends the message. I am able to send the by mail. I have checked all prerequisites

 if (videoUrl) {
      Share.open({
        message: 'Message,
        title: 'Title',
        url: `file://${videoUrl}`,
        type: 'video',
      })
        .then(res => {
          console.log(res);
        })
        .catch(err => {
          err && console.log(err);
        })
        .finally(() => {
          setLoading(false);
        });
    }

I did this and now it's working on both OS:

const shareVideo = React.useCallback(
    async (video: Video) => {
      let filePath = '';

      try {
        const file = await RNFetchBlob.config({
          fileCache: true,
          appendExt: 'mp4',
        }).fetch('GET', video.url, {});

        [filePath] = file.path().split('/RNFetchBlobTmp_');

        const customPath = `${filePath}/<app_name>.mp4`;

        const hasFile = await RNFetchBlob.fs.exists(customPath);

        if (hasFile) {
          RNFetchBlob.fs.unlink(customPath);
        }

        await RNFetchBlob.fs.mv(file.path(), customPath);

       await Share.open({
          title: `${translate('share')}...`,
          url: `file://${customPath}`,
          type: 'video/mp4',
        });Ï
      } catch (e: any) {
        toastError({
          message: e.message,
        });
      } finally {
        RNFetchBlob.fs.unlink(filePath);
      }
    },
    [toastError, translate],
  );

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and i will leave this open