B4J Question [B4J Server] Set predefined name of download from Fileserver

moster67

Expert
Licensed User
Longtime User
This is probably a browser related question although I am not 100% sure so I try to post my question here as well.

When using my B4J Server, in this case as a Fileserver for scanned documents, I noted that when my pdf-document is opened in Google Chrome and I click on the download button (upper right) to save the file on my computer, the name of my webage (in this case "docserver") is proposed as a filename for saving the file as you can see from below image:
upload_2018-1-18_22-58-54.png


I have used other Fileservers and when I want to save the pdf document opened in Crome, the name of the file is suggested as a predefined file-name.

I would like to achieve the same result i.e in this case the proposed name should be "PMI94088.pdf" and not "docserver".

This is my web-handler:

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
   
    Dim FileName As String = req.GetParameter("file")
    Dim In As InputStream = File.OpenInput("/mnt", FileName) 'su UBUNTU
       
    File.Copy2(In, resp.OutputStream)
       
End Sub

Any ideas?
 

moster67

Expert
Licensed User
Longtime User
Thanks - that got me in the right direction but not really what I wanted:

Using "attachment" will download the file directly without opening the file in the browser.
B4X:
resp.SetHeader("Content-Disposition", "attachment;filename=" & FileName)

whereas using "inline" will open the document (in my case a pdf) in the browser and when I click the download button to save the file, the filename will be proposed as the name of the file (just what I wanted):
B4X:
resp.SetHeader("Content-Disposition", "inline;filename=" & FileName)
 
Upvote 0
Top