将文件数据硬编码到网页中进行下载

时间:2016-05-30 08:43:07

标签: html5 hyperlink download

我有一个pdf文档,其路径已经硬编码到我的网页中。 我还有一个下载链接,点击用户可以下载文件。

<a href="Path\to\file" download>Click</a>    (Works in HTML5)

然而,无需单独携带网页代码和文件,是否可以将文件数据合并到网页本身,并在用户点击链接时形成可下载文件? < / p>

1 个答案:

答案 0 :(得分:0)

您可以尝试对该文件进行base64编码并将其添加为链接URL:

<a href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAV4AAACWCAYAAACW5+B3AAAKQWlDQ1BJQ0MgUHJvZmlsZQAASA2dlndUU9kWh8+9N73QEiIgJfQaegkg0jtIFQRRiUmAUAKGhCZ2RAVGFBEpVmRUwAFHhyJjRRQLg4Ji1wnyEFDGwVFEReXdjGsJ7601896a/cdZ39nnt9fZZ+9917oAUPyCBMJ0WAGANKFYFO7rwVwSE8vE9wIYEAEOWAHA4WZmBEf4RALU/L09mZmoSMaz9u4ugGS72yy/UCZz1v9/kSI3QyQGAApF1TY8fiYX5QKUU7PFGTL/BMr0lSkyhjEyFqEJoqwi48SvbPan5iu7yZiXJuShGlnOGbw0noy7UN6aJeGjjAShXJgl4GejfAdlvVRJmgDl9yjT0/icTAAwFJlfzOcmoWyJMkUUGe6J8gIACJTEObxyDov5OWieAHimZ+SKBIlJYqYR15hp5ejIZvrxs1P5YjErlMNN4Yh4TM/0tAyOMBeAr2+WRQElWW2ZaJHtrRzt7VnW5mj5v9nfHn5T/T3IevtV8Sbsz55BjJ5Z32zsrC+9FgD2JFqbHbO+lVUAtG0GQOXhrE/vIADyBQC03pzzHoZsXpLE4gwnC4vs7GxzAZ9rLivoN/ufgm/Kv4Y595nL7vtWO6YXP4EjSRUzZUXlpqemS0TMzAwOl89k/fcQ/+PAOWnNycMsnJ/AF/GF6FVR6JQJhIlou4U8gViQLmQKhH/V4X8YNicHGX6daxRodV8AfYU5ULhJB8hvPQBDIwMkbj96An3rWxAxCsi+vGitka9zjzJ6/uf6H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n0QUHj7iLNeSkACDRFQeBsKhqZIQAJ9EFB4+4izXkpAAg0RUHgbCoamSEACfRBQePuIs15KQAINEVB4GwqGpkhAAn0QUHj7iLNeSkACDRFQeBsKhqZIQAJ9EFB4+4izXkpAAg0RUHgbCoamSEACfRD4H/0Algt85TScAAAAAElFTkSuQmCC">DOWNLOAD</a>

但是向HTML添加文件源是最糟糕的事情。你为什么需要那个?您的HTML将慢慢加载非常CTRL + U和控制台调试将会非常慢。