反应本机共享图像 [英] React native share image
问题描述
我正在尝试通过各种可用设备的应用程序(例如 WhatsApp、Skype、电子邮件等)将从相机或图库拍摄的图像共享到其他设备我发现提供了共享"功能,但根据我的知识和研究,它只允许共享文本数据.
I am trying to share an image, either taken from camera or from gallery, to other devices through various available device's application's(eg whatsApp, skype, email etc.) I found the "Share" function provided but as per my knowledge and research, it only allows to share text data.
有人对通过本机应用程序共享图像有任何想法.
Has someone have any idea for sharing an image through a react native application.
提前致谢.
推荐答案
解决方案:
获取图片转base64的路径.
Get the path of the image to convert base64.
分享图片使用:react-native-share lib share
For share image use: react-native-share lib share
要访问设备目录,我建议使用:rn-fetch-blob.维基库
To access the device directories, I recommend using: rn-fetch-blob. Wikki lib
dwFile(file_url) {
let imagePath = null;
RNFetchBlob.config({
fileCache: true
})
.fetch("GET", file_url)
// the image is now dowloaded to device's storage
.then(resp => {
// the image path you can use it directly with Image component
imagePath = resp.path();
return resp.readFile("base64");
})
.then(async base64Data => {
var base64Data = `data:image/png;base64,` + base64Data;
// here's base64 encoded image
await Share.open({ url: base64Data });
// remove the file from storage
return fs.unlink(imagePath);
});
}
希望这会有所帮助.
这篇关于反应本机共享图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!