Android Question Get name of file from server?

aidymp

Well-Known Member
Licensed User
Longtime User
Hi,

OK so for a while I have been making apps that download files and as long as the link ends in a known extension its pretty reliable. however my users are now using dropbox and tinyurl combinations, I would like to implement it as it makes the users life easy. the question is!!

In most web browsers entering a tinyurl (to a direct file link) the browser will open the save window and show the correct file name!

So far I have always used the URL stripped down to the name and extension this has always worked but with all URL shorteners the file name isn't there! So i don't know the Name or the extension.

Obviously the server is supplying the name to web browsers so how can I read it?

Thanks
 

aidymp

Well-Known Member
Licensed User
Longtime User
Right! so after all the transplanting, and updating, modules, I now have what I had in the first post! lol

no actual filename, But I can see the type of file.

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Download http://tinyurl.com/y3lr927c
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
Job.Success = true
accept-ranges: [bytes]
connection: [Upgrade, Keep-Alive]
content-type: [application/vnd.android.package-archive]
date: [Thu, 11 Apr 2019 17:40:50 GMT]
etag: ["8e00c6-27dce9-585b7f02b3107-gzip"]
keep-alive: [timeout=5]
last-modified: [Thu, 04 Apr 2019 17:45:38 GMT]
server: [Apache]
transfer-encoding: [chunked]
upgrade: [h2,h2c]
vary: [Accept-Encoding,User-Agent]

But my browser, on PC, iOS, Android gives the filename! Shall I just take it that B4A cannot get this information?

Thanks
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Shall I just take it that B4A cannot get this information?
Looking at the OkHttp3 docs (the underlying library used by B4A's HttpJob/HttpUtils2), a response can have a priorResponse that could be useful in this case (since that Response object may contain the Location header information). The question would be how to access a OkHttpResponse object via Reflection/JavaObject to extract this response object (if available). Anyone?

Link: https://square.github.io/okhttp/3.x/okhttp/okhttp3/Response.html
 
Upvote 0
Top