Android Question file verification

drgottjr

Expert
Licensed User
Longtime User
technically, http HEAD could help you (search for okhttputils). it will indicate if the file was there, then you could act accordingly. but i'm finding an unexpected problem with it using okhttputils2. it's not something used normally, so i'm wondering if there is an issue with it. i'm going to look into it a little further, but perhaps someone else has something to contribute.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
wait, it occurs to me that HEAD will only return the response headers containing the information you need. when you run okhttputils2, it assumes you're expecting a payload (some kind of file). there is no payload with HEAD, just the headers, so okhttputils2 shows nothing, giving the impression it isn't working. you have to specifically ask for the headers. i'll put something together for you, unless someone else beats me to it. HEAD is the only way you can if some resource is on the server without actually downloading it. that's the way to go.
 
Last edited:
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
so here's what it would look like. the code is on the left, the log on the right. i made a HEAD request for an image. the server responded with (among other things) a reference to the file's size and mime type. that means the file i requested is there. if the file had not been there, there would have been an error. implementing this involves a couple other small steps, but the image will show that it's pretty quick and easy to find out if a resource is available.
 

Attachments

  • capture.png
    capture.png
    37.6 KB · Views: 88
Upvote 0
Top