I’m trying to insert a file in google drive using webRequest (since I’m implementing an resumable async upload), but I have no idea how to put data in request “body”.
From now, I have:
public static HttpWebRequest CreateUploadRequest(Google.Apis.Drive.v2.DriveService driveService, string uri, Stream contentStream, string title, string mimeType, string description = null)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "PUT";
Dictionary<string, object> requestBody = new Dictionary<string, object>();
requestBody["title"] = title;
requestBody["mimeType"] = mimeType;
if (!string.IsNullOrWhiteSpace(description))
{
requestBody["description"] = description;
}
driveService.Authenticator.ApplyAuthenticationToRequest(request);
Stream requestStream = request.GetRequestStream();
//How to do that???
requestStream.Close();
return request;
}
I set the headers for the HttpWebRequest, how the data of the body should be disposed?
And whats is the property name for the byte[] data of the file to be inserted?
Any example whould be appreciated.
The SDK documentation on this page says:
If you’ve never worked with it, RFC2387 is the MIME definition. Binary data in MIME is typically BASE64 encoded, like in this example from the RFC:
Have a look at this question for an example of uploading binary data to a Web request: Upload files with HTTPWebrequest (multipart/form-data)