0

I want to use that file for Web Share API but I do not want to select file from input tag.

I find out a solutions for solve my problem. this comment is close to what I looking for. (How to instantiate a File object in JavaScript?) But I want to create File object from mp4 local path, not string.

here is my code

import videoSrc from "./assets/video-example.mp4";

button.addEventListener("click", async () => {
  const file = new File([videoSrc], "filename.mp4", { type: "video/mp4" });
  await navigator.share({
    title: "Example video",
    text: "example video",
    files: [file],
  });
})

BUT I saw that file size does not match with actually size, and not working. I do not know why.

I try to many ways. such as convert to blob, to arrayBuffer, to base64String and create a new File object but it not work in client side.

How can I do that ?

xbique
  • 31
  • 4

0 Answers0