Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple APILearn More
mr-user1364292dWait! Does checking just the file size of the uploaded file actually allow pause/resume upload feature?
Fast-Nop33932292dI don't see why you'd even need that file token stuff. There is only one instance who actually knows whether an upload was successful, and that's the server, so the server should be asked.
I'd probably go for chunks of a defined size like up to 64k (except the last one, so the chunks need a data length field anyway) with appended CRC32. Now the kicker has to be that the chunks can be transmitted in any desired order, not with an ACK-NACK-protocol where latency would kill your throughput especially on mobile.
So the plot would be to initiate the upload, and since the client knows the file size, it knows how many chunks it will have, which it tells the server. The server can make a temporary directory like upload-yourfilename with chunk-x fragments and a file storing how many total chunks that should become, assemble that to yourfilename upon completion, and delete the directory.
Fast-Nop33932292dThe client could ask the server at any time which chunk numbers the server already has. Chunks with bad CRC would have been discarded immediately. The chunk list would be in the format of both ranges where possible and individual numbers where not. Like "yourfilename:1-10:13:17-20:24", indicating that chunks 11-12, 14-16 and beyond 24 are still missing.
Or, if a file is already complete on the server side and therefore no chunks are there, the server could return an answer like "yourfilename:DONE:N:X" with N being the file size in bytes and X its hash. This hash shouldn't be CRC32, rather something like SHA-256. That would allow the client to additionally check whether everything went fine, and even to compare its local file with the server version.
Ranchonyx8039291dWouldn't that fuck with the server if someone upstreams a massive file and then just pauses and leaves for a couple hours?
The server would just wait and waste valuable resources right?
Fast-Nop33932291d@Ranchu What resources? The ports? You'll always have the slow loris attack, but upon inactivity, the connection could be closed after a timeout. Resuming a partial download needs to work with a new connection anyway.
It shouldn't be a problem since the server can drop the connection and incomplete upload after a specific amount of time.