Skip to content

Commit

Permalink
fixed! (hopefully)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekqiu committed May 4, 2024
1 parent 8089773 commit 1b43f0d
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,23 +277,14 @@ shareFileButton.addEventListener("click", () => {
});

async function shareImage(imageUrl) {
console.log(`clicked shareImageAsset: ${imageUrl}`);
const fetchedImage = await fetch(imageUrl);
const blobImage = await fetchedImage.blob();
const fileName = imageUrl.split("/").pop();
const filesArray = [
new File([blobImage], fileName, {
type: "image/png",
lastModified: Date.now(),
}),
];
const shareData = {
files: filesArray,
};
if (navigator.canShare && navigator.canShare(shareData)) {
await navigator.share(shareData);
try {
const shareData = {
files: [new File([await (await fetch(imageUrl)).blob()], "persona.png", { type: "image/png" })],
};
navigator.share(shareData);
} catch (error) {
console.error("Error sharing the image: ", error);
}
// TODO implements a fallback to download the file
}

function preloadImages() {
Expand All @@ -320,4 +311,4 @@ function preloadImages() {
}

// Call the preloadImages function to preload the images
preloadImages();
preloadImages();

0 comments on commit 1b43f0d

Please sign in to comment.