I'm not exactly sure which category this question falls into (ABMaterial or simply the Jetty web server) as it impacts both.
Consider the following code. It is a slight variant from what Mashiane originally posted to download an excel file and works perfect for sending an excel file with an "xls" extension:
If I change the line of code with the extension to xlsx:
Instead of the file download prompt, the browser attempts to open the document in the browser.
I have a suspicion that it is caused by Jetty not knowing the MIME type for xlsx.
So my question is:
Is there a way to add this MIME type to Jetty, or is it possible to pass this parameter in the javascript line:
I know I could also achieve the same thing by adding a sending handler, or simply zipping up the excel file (as "zip" is also understood).
But wanted to know if MIME addition or javascript line modification would achieve the same results. Thank you.
Consider the following code. It is a slight variant from what Mashiane originally posted to download an excel file and works perfect for sending an excel file with an "xls" extension:
B4X:
page.Pause
'Excel Report developed in this area
'Report generation code goes here
'Excel Report development complete.
DateTime.DateFormat= "yyyy-MM-dd"
DateTime.TimeFormat="HHmm"
Dim stDateTime As String ="_" & DateTime.Date(DateTime.Now) & "_" & DateTime.Time(DateTime.now)
Dim outFileName As String = "Inventory_" & stDateTime & ".xls"
'save the file in the reports folder
Dim fPath As String = File.Combine(File.DirApp,"www/" & ABMShared.AppName.tolowercase & "/reports")
wb.Save(fPath, outFileName)
wb.Close
page.resume
' we want to execute a download of the file, open the document in a new browser tab
Dim pgLink As String = "../reports/" & outFileName
If ws.Open Then
'force a download of the document
ws.Eval("window.open(arguments[0],'_blank');", Array As Object(pgLink ))
ws.Flush
End If
If I change the line of code with the extension to xlsx:
B4X:
Dim outFileName As String = "Inventory_" & stDateTime & ".xlsx"
Instead of the file download prompt, the browser attempts to open the document in the browser.
I have a suspicion that it is caused by Jetty not knowing the MIME type for xlsx.
So my question is:
Is there a way to add this MIME type to Jetty, or is it possible to pass this parameter in the javascript line:
B4X:
ws.Eval("window.open(arguments[0],'_blank');", Array As Object(pgLink ))
I know I could also achieve the same thing by adding a sending handler, or simply zipping up the excel file (as "zip" is also understood).
But wanted to know if MIME addition or javascript line modification would achieve the same results. Thank you.