Right now the biggest problem we have is that some media hosting platforms don't provide exact files sizes in their API. So we can only heuristically estimate an approximate maximum size of the file (in case of derpibooru), or just know the exact upper limit of how much a file can weight (in case of twitter).
It's best to know the exact file size beforehand to select the most appropriate way to upload the file to telegram. So there are several ways to approach improving the efficiency of the current uploading process:
Fetch the headers for the file (e.g. using HTTP HEAD method) to figure out the Content-Length, and then decide how to upload file based on this
Pessimistically download the media content concurrently with trying to upload it via a direct URL to telegram. This way if uploading via direct URL fails, then we pay almost no performance penalty, because we were already downloading the media content while awaiting for the response from Telegram
Right now the biggest problem we have is that some media hosting platforms don't provide exact files sizes in their API. So we can only heuristically estimate an approximate maximum size of the file (in case of derpibooru), or just know the exact upper limit of how much a file can weight (in case of twitter).
It's best to know the exact file size beforehand to select the most appropriate way to upload the file to telegram. So there are several ways to approach improving the efficiency of the current uploading process:
Content-Length
, and then decide how to upload file based on this