【发布时间】:2020-07-12 10:04:20
【问题描述】:
如何通过使用 react-native 的链接将视频直接分享到 Facebook/Instagram/twitter。我正在使用 react-native-share 在 Instagram/Facebook 上分享视频,但这是作为链接分享的,但我想像 TikTok 一样将它们作为视频分享。
我怎样才能做到这一点?我知道它可以通过将其转换为 base 64 来实现,那么是否有任何库可以直接将链接转换为 base 64?否则我需要先下载它然后检索它然后转换为base 64然后分享它。
请帮忙!
如果有人需要完整代码,将回答我是如何做到的:
shareURL = async (socialMedia) => {
let facebook = socialMedia === 'facebook'
let twitter = socialMedia === 'twitter'
const { video, uploadingStatus } = this.state;
this.setState({ isSliderModalVisible: true }, async () => {
let uploadOptions = { fileCache: true, appendExt: 'mp4', timeout: 60000, indicator: true, IOSBackgroundTask: true, }
const res = await RNFetchBlob.config(uploadOptions).fetch('GET', video, {})
.progress((received, total) => {
this.setState({ uploadingStatus: (received / total) * 100 })
console.log('Progress', (received / total) * 100);
})
const filePath = res.path(); //to delete video
const base64String = await res.base64();
const url = `data:video/mp4;base64,${base64String}`;
await RNFetchBlob.fs.unlink(filePath); //deleted the video from path of celebfie.
this.setState({ isSliderModalVisible: false })
setTimeout(() => {
const shareOptions = {
title: 'Celebfie',
message: hashtags,
subject: 'Sharing my intro video which I recorded in Celebfie.',
url: url,
type: 'video/mp4',
social: facebook ? Share.Social.FACEBOOK : twitter ? Share.Social.TWITTER : Share.Social.INSTAGRAM
};
Share.shareSingle(shareOptions).then((res) => this.setState({ sharedVideoToSocialNetwork: true }))
.catch((err) => { Global.customToast('Video sharing failed.', 'failure') })
})
}, 1000);
}
【问题讨论】:
标签: facebook react-native twitter instagram