Good afternoon, tell me how best to implement resuming the file on the server. Does the server accept file size and name (I work through socket)?

  • one
    The client calculates the hash amount of the file being sent (and is stored on the server, for example, by adding to the file name). It, and not the file name, is the file identifier, since with the same name a completely different file can be sent afterwards or the same, but already with changes. After breaking the connection, the hash is sent back to the server and is searched for it. If there is such a file, then, accordingly, its size is returned. Then you transfer to what offset in the file to begin the transfer of data. - Max ZS
  • one
    In general, resuming is necessary for real long-term breaks and outages. With short-term loss of connection (and this may be a minute or two), the client and server "solve" everything themselves at the TCP protocol level, focusing on the corresponding socket options. - Max ZS
  • one
    @MaxZS, to calculate the hash throughout the file, if it is very large, it can be expensive. In this case, it is better to send some UUID that will uniquely identify each specific file. Well, whether the file is the same after the break or whether it is an updated download, which should be assigned a new identifier, let the client bear the responsibility. - alexis031182
  • @ alexis031182 Uploading a large file is also expensive. And the hash calculation algorithms are different. Yes. Some will be faster and there will be a probability of collisions. But it is a blunder to shift responsibility to the client. Always when working with a network, consider that on the other hand, either a hacker or a fool (and not only the network). - Max ZS
  • @ alexis031182 And an example of the fact that the user cannot be blamed on the following algorithm. I upload an important text document (even if it is under-downloaded it will open, although this can be attributed to many other formats). And then suddenly I remember that I forgot to change one important figure. I cut off the download. I am changing. I upload again. As a result, the server is an old document. Those people to whom this document was needed / important, deflate the "old". And it gets all the bumps from the fact that the document is not correct. Others lose in fact, not the client who downloaded it. He is sure that he has uploaded a new one. - Max ZS

1 answer 1

you can do it this way: when a request comes in to the server to upload a file - check if there is this file, if not, write down the corresponding, unique user line, and write the current position in the file at each portion of sent bytes. if the file already exists then send the position in the file + permission to the client. but a better option with a hash, as already mentioned above