Downloads the content of a file by ID. (In this example the file id = 1R_70heIyzIAu1_u0prXbYcaIiJRVkgBl) The file is streamed directly to the filesystem. Note: The alt=media query param must be used to download the file content (as opposed to the file metadata).
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
set rest = Server.CreateObject("Chilkat_9_5_0.Rest")
' Provide a previously obtained OAuth2 access token.
set oauth2 = Server.CreateObject("Chilkat_9_5_0.OAuth2")
oauth2.AccessToken = "OAUTH2_ACCESS_TOKEN"
success = rest.SetAuthOAuth2(oauth2)
success = rest.Connect("www.googleapis.com",443,1,1)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"
End If
success = rest.AddQueryParam("includeTeamDriveItems","true")
success = rest.AddQueryParam("supportsTeamDrives","true")
success = rest.AddQueryParam("alt","media")
' First send the HTTP request.
success = rest.SendReqNoBody("GET","/drive/v3/files/1R_70heIyzIAu1_u0prXbYcaIiJRVkgBl")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"
End If
' Read the response header. If the response status code is success, stream to the file.
' Otherwise receive the error response text.
statusCode = rest.ReadResponseHeader()
If (statusCode < 0) Then
Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"
End If
If (statusCode <> 200) Then
Response.Write "<pre>" & Server.HTMLEncode( "Received error response code: " & statusCode) & "</pre>"
' Read the error response body.
set sbErrResponse = Server.CreateObject("Chilkat_9_5_0.StringBuilder")
success = rest.ReadRespSb(sbErrResponse)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"
End If
Response.Write "<pre>" & Server.HTMLEncode( "Error response:" & sbErrResponse.GetAsString()) & "</pre>"
End If
' Stream the response body to the output file.
set respBodyStream = Server.CreateObject("Chilkat_9_5_0.Stream")
respBodyStream.SinkFile = "/someDirectory/penguins.jpg"
success = rest.ReadRespBodyStream(respBodyStream,1)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"
End If
Response.Write "<pre>" & Server.HTMLEncode( "Example Completed.") & "</pre>"
%>
</body>
</html>