-1

This works totally fine in most browsers:

<a href="file url" target="_blank" download>Click to download</a>

When someone clicks, the file is downloaded.

But when someone is using the Instagram or Tik Tok in-app browser the file is opened on the browser and unable to be downloaded.

Jacin
  • 71
  • 9
  • Likely dupe: https://stackoverflow.com/questions/60522840/html-download-attribute-redirects-to-url-instead-of-downloading – mplungjan Jan 03 '21 at 18:44
  • @mplungjan thank you. I assume there is no way to do this if the file is in different domains – Jacin Jan 03 '21 at 18:55

1 Answers1

0
<a download="name_of__file" href="path/to/the//file"> This will do</a>

This should do, if you know the URLs. Else it is much more complicated

From the web

 function downloadFile(data, fileName, type="text/plain") {
 // Create an invisible A element
 const a = document.createElement("a");
 a.style.display = "none";
 document.body.appendChild(a);

  // Set the HREF to a Blob representation of the data to be downloaded
  a.href = window.URL.createObjectURL(
   new Blob([data], { type })
   );

   // Use download attribute to set set desired file name
   a.setAttribute("download", fileName);

   // Trigger the download by simulating click
   a.click();

   // Cleanup
   window.URL.revokeObjectURL(a.href);
    document.body.removeChild(a);
   }
ptts
  • 1,022
  • 8
  • 18