我有一个 SAFE 堆栈应用程序。我需要使用户能够上传和下载文件。
利用上传作品
Browser.Dom.FileReader.Create()
有没有相应的方法可以让用户下载文件?
这个答案提供了一个使用完全不同的机制的解决方案,它依赖于一个 js 库。是否没有与该FileReader
方法相对应的机制?
我想出了以下似乎对我有用的方法。
let downLoad fileName fileContent =
let anchor = Browser.Dom.document.createElement "a"
let encodedContent = fileContent |> sprintf "data:text/plain;charset=utf-8,%s" |> Fable.Core.JS.encodeURI
anchor.setAttribute("href", encodedContent)
anchor.setAttribute("download", fileName)
anchor.click()