0

I am working on a download manager in C# integrated Chrome. When I try to download from google drive the response doesn't return a Content-Length and this means -1 (Unknown). But IDM gets the correct size and I couldn't understand how. Anyone knows please help!

The file in this url: https://drive.google.com/uc?export=download&confirm=-wOm&id=1gC_fEKIlv9oaLQUAKH4GvRvAIqhDgAbz

Response headers:

X-GUploader-UploadID = AAANsUmzer2D7sJF5ROkgKYHrAfB994uetArTRtS2O1-2rcomguwXU2nVQ20nghtQbf4KHWoxVN8XQGlPSS_hj3hw1A
Access-Control-Allow-Origin = *
Access-Control-Allow-Credentials = false
Access-Control-Allow-Headers = Accept, Accept-Language, Authorization, Cache-Control, Content-Disposition, Content-Encoding, Content-Language, Content-Length, Content-MD5, Content-Range, Content-Type, Date, GData-Version, google-cloud-resource-prefix, x-goog-request-params, Host, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, Origin, OriginToken, Pragma, Range, Slug, Transfer-Encoding, hotrod-board-name, hotrod-chrome-cpu-model, hotrod-chrome-processors, Want-Digest, x-chrome-connected, X-ClientDetails, X-Client-Version, X-Firebase-Locale, X-Goog-Firebase-Installations-Auth, X-Firebase-Client, X-Firebase-Client-Log-Type, X-GData-Client, X-GData-Key, X-GoogApps-Allowed-Domains, X-Goog-AdX-Buyer-Impersonation, X-Goog-Api-Client, X-Goog-AuthUser, x-goog-ext-124712974-jspb, x-goog-ext-251363160-jspb, x-goog-ext-259736195-jspb, X-Goog-PageId, X-Goog-Encode-Response-If-Executable, X-Goog-Correlation-Id, X-Goog-Request-Info, X-Goog-Request-Reason, X-Goog-Experiments, x-goog-iam-authority-selector, x-goog-iam-authorization-token, X-Goog-Spatula, X-Goog-Travel-Bgr, X-Goog-Travel-Settings, X-Goog-Upload-Command, X-Goog-Upload-Content-Disposition, X-Goog-Upload-Content-Length, X-Goog-Upload-Content-Type, X-Goog-Upload-File-Name, X-Goog-Upload-Header-Content-Encoding, X-Goog-Upload-Header-Content-Length, X-Goog-Upload-Header-Content-Type, X-Goog-Upload-Header-Transfer-Encoding, X-Goog-Upload-Offset, X-Goog-Upload-Protocol, x-goog-user-project, X-Goog-Visitor-Id, X-Goog-FieldMask, X-Google-Project-Override, X-Goog-Api-Key, X-HTTP-Method-Override, X-JavaScript-User-Agent, X-Pan-Versionid, X-Proxied-User-IP, X-Origin, X-Referer, X-Requested-With, X-Stadia-Client-Context, X-Upload-Content-Length, X-Upload-Content-Type, X-Use-HTTP-Status-Code-Override, X-Ios-Bundle-Identifier, X-Android-Package, X-Ariane-Xsrf-Token, X-YouTube-VVT, X-YouTube-Page-CL, X-YouTube-Page-Timestamp, X-Compass-Routing-Destination, X-Goog-Meeting-Botguardid, X-Goog-Meeting-ClientInfo, X-Goog-Meeting-ClientVersion, X-Goog-Meeting-Debugid, X-Goog-Meeting-RtcClient, X-Goog-Meeting-Token, X-Goog-Meeting-StartSource, X-Client-Data, X-Sfdc-Authorization, MIME-Version, Content-Transfer-Encoding, X-Earth-Engine-App-ID-Token, X-Earth-Engine-Computation-Profile, X-Earth-Engine-Computation-Profiling, X-Play-Console-Experiments-Override, X-Play-Console-Session-Id, x-alkali-account-key, x-alkali-application-key, x-alkali-auth-apps-namespace, x-alkali-auth-entities-namespace, x-alkali-auth-entity, x-alkali-client-locale, EES-S7E-MODE, cast-device-capabilities
Access-Control-Allow-Methods = GET,OPTIONS
Content-Disposition = attachment;filename="[saglamindir.net]VirtualBox-6.1.2.rar";filename*=UTF-8''%5Bsaglamindir.net%5DVirtualBox-6.1.2.rar
X-Goog-Hash = crc32c=C7PP8g==
Transfer-Encoding = chunked
Alt-Svc = h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
Connection = close
Cache-Control = private, max-age=0
Content-Type = application/rar
Date = Sat, 08 Aug 2020 21:16:02 GMT
Expires = Sat, 08 Aug 2020 21:16:02 GMT
Server = UploadServer

enter image description here

Ali Tor
  • 2,772
  • 2
  • 27
  • 58

1 Answers1

1

You have not posted your code to review your issue. However, you should consider two things in Google Drive requests. First you should use Google APIs to process the requests. This means, you'll have to have an authenticated requests through OAuth2 protocols.

If you're using their NuGets, then you can simply use the DriveService to get the file size.

var file = service.Files.Get(fileId).Execute();
var size = file.FileSize;

if you're using HttpWebRequest or HttpClient (with the aproperiate headers and authenticated request), your response would be GZip encoded (Check Transfer-Encoding) therefore, your response's body length will be always less than the actual bytes length. You'll need to decode it to get the correct length. (Check HttpWebRequest.AutomaticDecompression OR HttpClientHandler.AutomaticDecompression

you can apply the decompression like this :

HttpWebRequest

var request = (HttpWebRequest) WebRequest.Create(fileUrl);
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
// your code

HttpClient

var handler = new HttpClientHandler()
{
    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
};        
var client = new HttpClient(handler);
// your code
iSR5
  • 3,274
  • 2
  • 14
  • 13
  • Hi I couldn't find `Execute` method in API. Which API contains that method? – Ali Tor Aug 17 '20 at 22:05
  • @AliTor it's within `DriveService` you need to reference `Google.Apis.Drive.v2` (v2 or v3, both have them). – iSR5 Aug 18 '20 at 01:17