Hello, I am looking to share images using the new API. When I have an upload form for a file, I can easily share that file with the API. However, I am having trouble trying to share a local file. Here is my attempt:
function sharePage(){
const title = document.title;
var filesArray = [];
$.get(baseurl+"images/cover.jpg", { async: false }, function(data) { filesArray.push(data); });
setHashtag('share');
if(navigator.share){
if(navigator.canShare && navigator.canShare({ files: filesArray })) {
navigator.share({
text: 'FILE',
files: filesArray,
title: title,
url: baseurl
});
}else{
navigator.share({
text: 'NO FILE',
title: title,
url: baseurl
});
}
}else{
document.location.href="whatsapp://send?text="+baseurl;
}
EDIT: The problem I'm facing is that I don't know how to implement a server-side file into this script. Something like var file = baseurl+"images/cover.jpg"; I tried using jQuery $.get but it didn't work.