B4J Question [WebApp] Download from https

Fabrice La

Active Member
Licensed User
Longtime User
In my [WebApp] I am working with database and I created a excel file.

Now I what that people can download it.

My [WebApp] is in https:// and if I try
B4X:
Dim J As HttpJob
    J.Initialize("J", Me)

    J.Download(https://my.website.com:12345/myfile.xls)
I have an error
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
 

Fabrice La

Active Member
Licensed User
Longtime User
I would like to be able to create the xls file (done) and open popup (or something else) to the user to download the file ?...
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
Ok I saw that but I am not using httpclient but only httpjob to dowload the file inside my WebApp.
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
Ok may be wrong I am taking ....

I saw in TableHelper module :
B4X:
resp.ContentType = "application/vnd.ms-excel"
    resp.SetHeader("Content-Disposition", "attachment;filename=table.xls")
    Dim In As InputStream = File.OpenInput(File.DirTemp, fileName)
    File.Copy2(In, resp.OutputStream)

But this tableHelper module is Class Module

I am using a Websocket module How I can do the same as this code
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Ok I saw that but I am not using httpclient but only httpjob to dowload the file inside my WebApp.
You should use HttpUtils2 source code instead of the library and modify it to accept all certifications.

The source code is included in the server example: [WebApp] Web Apps Overview

You need to modify HttpUtils2Service.
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
Thanks again Erel. Works.

I if I do :
B4X:
Sub JobDone(Job As HttpJob)
  If Job.Success = True Then
          Dim OutStream As OutputStream 
        If os.Contains("win") Then
          OutStream = File.OpenOutput(File.DirApp & "\..\", File.GetName(link1), False)
        Else If os.Contains("mac") Then
            OutStream = File.OpenOutput(File.DirApp & "/", File.GetName(link1), False)
        Else  If os.Contains("nux") Then
          OutStream = File.OpenOutput(File.DirApp & "/", File.GetName(link1), False)
        End If
       
        File.Copy2(Job.GetInputStream, OutStream)
        OutStream.Close
The file is copied in the website. How I can copy it localy ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is almost never a need to check the current platform.

You can use '/' and it will work on all platforms. Or better:
B4X:
Dim outStream As OutputStream = File.OpenOutput(File.DirApp, File.GetName(link1), False)

The file is copied in the website. How I can copy it localy ?
Are you connecting from a B4A app?
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
Ok but how the server deliver the file ? I have 2 applications where I create a Excel file and I would like that the user choose where to save the file.
The first one is B4J application I am using filechooser.ShowSave Is it correct ? How must be the syntax ?
The second is B4J WebAppli I don't know how to handle the download.
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
I blow my head out to find how the filechooser is working !!
In my code I have :
B4X:
newWorkbook.Write
        newWorkbook.Close
        Dim fc As FileChooser
        fc.Initialize
        fc.InitialFileName = "excelfile.xls"
        fc.SetExtensionFilter("Excel Files",Array As String("*.xls"))
        Dim fileName As String = fc.ShowSave(MainForm)
        If fileName <> "" Then
            If fileName.ToLowerCase.EndsWith(".xls") = False Then fileName = fileName & ".xls"
            Dim out As OutputStream = File.OpenOutput("", fileName, False)
            'What to put HERE !!!!
            out.Close
            Log("File saved: " & fileName)
        End If

I did not find exemple to save file using filechooser.
And it must so easy .....
 
Upvote 0
Top