I want to allow a plugin user to download a file, PDF, log file, etc.
Anyone know how HST's web server works to allow a file download via browser?
Anyone know how HST's web server works to allow a file download via browser?
If this is your first visit, be sure to check out the FAQ. You must register before you can post.
IMPORTANT: Your first post will be checked for appropriate content. This may take a bit of time.
Public Function GetLogs() As String Dim response As String Try response = IO.File.ReadAllText(g_debugFile) If (response Is Nothing) Then response = "No logs found." End If Catch ex As Exception response = "Unable to get log file: " & g_debugFile & " " & ex.Message End Try Return response End Function
<% Response.ContentType = "application/x-msexcel" Response.AppendHeader("Content-Disposition", "attachment; filename=test.xlsx") Response.TransmitFile(Server.MapPath("~/MyPluginFolder/test.xlsx")) Response.End() %>
<% Response.ContentType = "application/pdf" Response.AppendHeader("Content-Disposition", "attachment; filename=test.pdf") Response.TransmitFile(Server.MapPath("~/MyPluginFolder/test.pdf")) Response.End() %>
var element = document.createElement('a'); element.setAttribute('href', 'data:csv/plain;charset=utf-8,' + encodeURIComponent(response)); element.setAttribute('download', "MyFile.csv"); element.style.display = 'none'; document.body.appendChild(element); element.click(); document.body.removeChild(element);
function downloadFile() { var filename = "MyFile.pdf"; fetch(window.location.origin + "/MyPluginFolder/" + filename) .then(resp => resp.blob()) .then(blob => { const url = window.URL.createObjectURL(blob); const element = document.createElement('a'); element.style.display = 'none'; element.href = url; element.download = filename; //Change if the name of the downloaded file should be different document.body.appendChild(element); element.click(); window.URL.revokeObjectURL(url); //Done, file could be deleted alert('Your file should be downloaded.'); }) .catch(() => alert('Error while downloading file.')); }
Comment