我是Javascript和Ionic框架的新手。我想使用 SocialShare Plugin共享一个路径为"/assets/input.json“的本地文件,我想通过应用程序将这个扩展名为.json的本地文件共享到一个.txt文件中。
谁能帮助我应该如何使用这个插件来访问我的本地文件,以及如何将其转换为文本文件以共享它。
发布于 2020-09-15 15:15:11
尝试这个参考:https://www.npmjs.com/package/cordova-plugin-x-socialsharing
var options = {
message: 'share this', // not supported on some apps (Facebook, Instagram)
subject: 'the subject', // fi. for email
files: ['', ''], // an array of filenames either locally or remotely
url: 'https://www.website.com/foo/#bar?a=b',
chooserTitle: 'Pick an app', // Android only, you can override the default share sheet title
appPackageName: 'com.apple.social.facebook', // Android only, you can provide id of the App you want to share with
iPadCoordinates: '0,0,0,0' //IOS only iPadCoordinates for where the popover should be point. Format with x,y,width,height
};对于从.json到.txt的文件转换,您可以使用js (https://www.websparrow.org/web/how-to-create-and-save-text-file-in-javascript)和离子库https://ionicframework.com/docs/native/file读写文件
发布于 2020-10-08 22:06:22
而不是社交共享,我建议使用Filesharer,在社交共享中,我真的很怀疑你能从你的文件夹中共享一个本地文件。我也有类似的要求,Filesharer是一个完美的插件,下面是你可以尝试的代码。
async shareLocalFile() {
console.log('Sharing files...')
this.http.get('/assets/input.json', { responseType: 'blob'})
.subscribe( res => {
const reader = new FileReader();
reader.onloadend = () => {
const result = reader.result as string;
const base64Data = result.split(',')[1]
FileSharer.share({
filename: 'input.txt',
base64Data,
contentType:'application/txt'
});
}reader.readAsDataURL(res);
})
}
https://stackoverflow.com/questions/63862388
复制相似问题