Android Question httpjob unable to get the filename

DonManfred

Expert
Licensed User

DonManfred

Expert
Licensed User
headers:content-disposition:[attachment; filename*=UTF-8''test.odt; filename="test.odt"]
This is a line of the headers when calling

B4X:
    Dim url As String = "https://www.leslulus.com/nextcloud/index.php/s/stCoQ6WBTkqBXNx/download"
   
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(url)
    '    j.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim resp As OkHttpResponse = j.Response
        Dim list1 As Map
        list1 = resp.GetHeaders
        For i = 0 To list1.Size - 1
            Log("headers:" & list1.GetKeyAt(i) & ":" & list1.GetValueAt(i))
        Next
           
        Dim filename As String
        filename = url.SubString(url.LastIndexOf("/"))
               
        Dim su As StringUtils
        filename = su.DecodeUrl(filename,"UTF8")
        Log(filename)
               
        Dim out As OutputStream = File.OpenOutput(File.DirInternal, filename, False)
        File.Copy2(j.GetInputStream, out)
        out.Close '<------ very important
       
        Log(File.ListFiles(File.DirInternal))
   
    End If
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
headers:cache-control:[must-revalidate, post-check=0, pre-check=0]
headers:connection:[Keep-Alive]
headers:content-disposition:[attachment; filename*=UTF-8''test.odt; filename="test.odt"]
headers:content-length:[7938]
headers:content-security-policy:[default-src 'self'; script-src 'self' 'nonce-MWJUQytTSjlKcDVGNUlhcm1uZmx1Yy9YTENXN1ViTFdqQm00a0hiQ1FnOD06cC9PNjFuVWVYUGNUZ2RMenl3Mk95cG5tWWhMZE9NTzQ2blh0NEVPZ0Izcz0='; style-src 'self' 'unsafe-inline'; frame-src *; img-src * data: blob:; font-src 'self' data:; media-src *; connect-src *; object-src 'none'; base-uri 'self';]
headers:content-transfer-encoding:[binary]
headers:content-type:[application/vnd.oasis.opendocument.text]
headers:date:[Thu, 19 Sep 2019 05:06:09 GMT]
headers:expires:[0]
headers:keep-alive:[timeout=5, max=100]
headers:pragma:[public]
headers:referrer-policy:[no-referrer]
headers:server:[Apache]
headers:set-cookie:[ocyj8vfads4b=8vk4qf9ucsmj3vljjvd47oqod5; path=/nextcloud; secure; HttpOnly, oc_sessionPassphrase=uIweZITSTjLPi93LjIaoKFe6yZyUNYCOPc11yTm41WS5O8JXrDhu%2BsX%2Fi4P18JaPyNYE3yUy1MQ1aOgNw8aUy20c9YDHjCJKVrB%2BIgx7%2BYs4ba3kEswBY6c9n4QRf%2FZl; path=/nextcloud; secure; HttpOnly, nc_sameSiteCookielax=true; path=/nextcloud; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax, nc_sameSiteCookiestrict=true; path=/nextcloud; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=strict]
headers:strict-transport-security:[max-age=31536000; includeSubDomains]
headers:x-content-type-options:[nosniff]
headers:x-download-options:[noopen]
headers:x-frame-options:[SAMEORIGIN]
headers:x-permitted-cross-domain-policies:[none]
headers:x-robots-tag:[none]
headers:x-xss-protection:[1; mode=block]
/download
(ArrayList) [stCoQ6WBTkqBXNx, download]
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
headers:content-disposition:[attachment; filename*=UTF-8''test.odt; filename="test.odt"]
this is the headerline you need to parse and extract the filename

Note that i suffixed the url with "/download" to get this result
 

ludogomez

Member
Licensed User
Thanks for the response,

I try with my server and I did not see the good header, my bad.

But for my app, I'll try another server but :
  • it's a microsoft tecnhology (ASPNET)
  • it's not my server
  • I must connect with a login/password
I can't reproduce easily this behaviour :

this the headers:

B4X:
headers:cache-control:[private]
headers:cf-ray:[5189114a1d0cc84f-AMS]
headers:content-encoding:[gzip]
headers:content-type:[text/html; charset=utf-8]
headers:date:[Thu, 19 Sep 2019 05:12:56 GMT]
headers:expect-ct:[max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"]
headers:server:[cloudflare]
headers:x-aspnet-version:[4.0.30319]
headers:x-content-type-options:[nosniff]
headers:x-powered-by:[ASP.NET]
Thanks
 
Top