Android Question Determine data type of httpjob download

JdV

Active Member
Licensed User
Longtime User
Hello

Is it possible to determine what type of data has been downloaded by httpjob?

For example, the following code will successfully download whatever 'somefile' is however it will error if it isn't a bitmap:

Download bitmap:
    Dim myBMP as Bitmap

    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("https://somewhere/somefile")
    Wait For (j) JobDone(j As HttpJob)
    
    If j.Success Then myBMP = j.GetBitmap

Is there a test that can be carried out on the downloaded data to see what the data is before processing it further?

E.g. Something along the lines of:
If j.DataType = "PNG" then Log("PNG file download")
If j.DataType = "text" then Log("Text file downloaded")

Or if the downloaded data were written to a file, is there something that can say if the file is text, jpeg, PNG, zip, etc. (obviously without relying on the file extension)?

Regards

Joe
 

DonManfred

Expert
Licensed User
Longtime User
You can use the TAG of the httpjob to store information on what is coming.
j.GetBitmap only works if the result IS an Image.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Is there a test that can be carried out on the downloaded data to see what the data is before processing it further?

Yes, and no. All valid PNG files begin with the same eight byte signature. Having downloaded a file you can certainly check for this signature, and if it is present you can be fairly sure that it is a PNG. However someone could write a file that starts with a PNG signature that is not a PNG file.

Many other file types have similar signatures, although often there are variations. But there are hundreds of different file formats, and it would not be sensible to consider writing a "file inspector" that could detect all of them. But in the real world a simple check for a specific type, or for a couple of alternatives, is good enough.
 
Upvote 0
Top