Android Question File upload clarifications

AlpVir

Well-Known Member
Licensed User
Longtime User
With these instructions I upload a file :
B4X:
Dim HttpClient1                 As HttpJob
If Not(HttpClient1.IsInitialized) Then HttpClient1.Initialize("HttpClient1",Me)
HttpClient1.PostFile("https://NameSite,NameFolder,NameFile)
With these others I check if the file has actually been sent on the web :
B4X:
Sub JobDone (Job As HttpJob)
    If Job.Success = True Then
        Select Job.JobName
            Case "HttpClient1"
                            '--- XXX
The question is : in point "XXX" can I be 1000% sure that the whole file - I repeat: the whole file - has been totally downloaded ?
Or, to be absolutely certain, should I download and verify the exact correspondence between the two files, the one sent on the internet and the one received from the internet ?
Thank in advance
 

drgottjr

Expert
Licensed User
Longtime User
point XXX must, of necessity, mean receipt of a signal from the
server that transmission is complete. if you do not receive that
signal or if you receive some other signal, there was a problem
with transmission.

you are dependent on the tcp/ip protocol. barring an attack,
"success" means a faithful transmission of the resource. this
is really the basis of the internet, and it is called into play millions
of time a day. we would have nothing without the protocol.
if your software does not conform to the protocol, you will have a
hard time communicating with other hosts.

assuming you have not experienced an attack of some sort
(eg, "man in the middle"), when you (the client) receives a
"success" signal from the server, you can assume the resource
that you received is integrally the same as the resource you
requested from the server.

this is based on a number of factors. you should read about the
tcp/ip protocol for a full explanation. the dialog between server
and client is based on error correction for each packet transmitted.
the server tells the client what the crc value of the packet is, and the
client computes a crc based on the data it received in the packet.
if the crc's do not match, the server will resend the packet. this goes
on until all packets have been transmitted faithfully. at this point, the
server will indicate "success" and initiate the disconnect.

if the network connection is interrupted, you won't receive "success"
(some clients, eg okhttpclient, can automatically re-establish the
connection and try again). if you receive "success" but are the victim
of an attack, you will have no way of knowing that you have been attacked,
so there is nothing you can do in this regard. trying to download again
would seem fruitless.

when you download software from some sites, a signature is published.
after downloading the resource, you can use the signature to confirm
its authenticity. this is similar to what happens between server and
client. but the site itself may have been hacked, so a signature is only
as good as the site's integrity.

even if you receive "success" from the server, there could be a problem
regarding how you interpret the data. if the server is sending binary data
and you interpret the data as a string of characters, you will appear to have
garbage. this is not the server's fault. part of the http protocol involves
the server and the client letting each other know what kind of data are
being transferred. again, a protocol to follow.
 
Upvote 0
Top