B4J Tutorial [Server] Upload files from your B4A app to your B4J server over the internet

Discussion in 'B4J Tutorials' started by Erel, Jan 28, 2014.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    This is not specific to this solution. This is how the internet works...
     
  2. upsis

    upsis Member Licensed User

    What changes should I make to the FileServer-B4j example can be published on my internet service provider? Thanks
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Do you have an online server?
     
  4. upsis

    upsis Member Licensed User

    Yes, we have.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    The only change you need is to disable the dynamic dns function (disable UpdateIp timer).
     
  6. driesvp

    driesvp Member Licensed User

    When selecting a photo to upload, quite often the photo isn't uploaded. Sometimes after retrying several times, it works.
    I notice in debugger mode that when this happens the screen "Waiting for IDE-debugger to connect" appears. When the photo succesfull uploads, this screen does not appear.

    Any idea what causes this?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    This issue happens when the OS kills the process while the third party picker is visible. The solution is to add a service and call Service.StartForeground to prevent it from being killed.
     
  8. granmaestro

    granmaestro Member Licensed User

    please,

    can you explain this : Create a new Download handler. Open an InputStream and use File.Copy2 to copy it to the response OutputStream.

    thank you
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Files stored under the www folder are served automatically. If you want to allow other files to be downloaded then you should use a custom handler.

    For example you can use this code to create a handler that sends a file from c:\temp to the client. The file name is passed in the query (www.example.com?file=test1.jpg)
    Code:
    Sub Handle(req As ServletRequest, resp As ServletResponse)
       
    Dim FileName As String = req.GetParameter("file")
       
    Dim In As InputStream = File.OpenInput("c:\temp", FileName)
       
    File.Copy2(In, resp.OutputStream)
    End Sub
     
    Philip Prins and lemonisdead like this.
  10. granthierry

    granthierry Member Licensed User

    Thank you Erel,

    If i understand : the server send the file. ( i usually use ftp connection )
    And before the client send a request.

    I don't know if i can make the request.

    Thank you
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Http servers respond to client requests. The client sends a request with HttpUtils2 and the server responds with the file.
     
  12. granthierry

    granthierry Member Licensed User

    Ok

    Thank you
     
  13. Fabrice La

    Fabrice La Active Member Licensed User

    How to use this example in ssl (https://) ? to avoid :

    Error: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
     
  14. Erel

    Erel Administrator Staff Member Licensed User

  15. Fabrice La

    Fabrice La Active Member Licensed User

    I know this tutorial for Server.
    This error
    Error: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
    is from B4A on device try to upload file to ssl server. I am using example "FileClient-B4A" and try to upload to ssl Server.
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    You need to initialize HttpClient with hc.InitializeAcceptAll (HttpUtils2Service).
     
  17. Fabrice La

    Fabrice La Active Member Licensed User

    I did add :
    Code:
    Dim su As StringUtils
            
    Dim j As HttpJob
            
    Dim hc As HttpClient
            hc.InitializeAcceptAll(
    "hclient")
            j.Initialize(
    "file", Me)
            link = link & spbox.SelectedItem & 
    "/"
            j.PostBytes(link & 
    "?type=file&name=" & su.EncodeUrl(FileName, "UTF8"), _
                out.ToBytesArray)
    No success
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    You need to add HttpUtils2 source code instead of the library and modify HttpUtils2Service. Creating a new HttpClient will not have any effect on the jobs you send.
     
  19. Fabrice La

    Fabrice La Active Member Licensed User

  20. LucaMs

    LucaMs Expert Licensed User

    I tried calling 127.0.0.1:54021/test and it seems to work ("Your ip address: 127.0.0.1").

    Then (my router's ip): xxx.xxx.xxx.xxx:54021/test - failed.

    I have 1 active port forwarding:

    Private IP: <MyPC IP - it is fixed>
    Protocol Type: TCP
    Public Start Port: 54021
    Public End Port: 54021
    Connection: PVC0

    I also tried disabling both the firewalls (router & pc)

    In the client code (I get a "connection timeout") i have:
    Private link As String = "http://xxx.xxx.xxx.xxx:54021/upload" (xxx... is my router's ip)

    Note that ping (from client) responds.
     
    Last edited: Jul 24, 2014
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice