问题
I want to try upload file google drive and my code is here:
public static File UploadFile(DriveService service, string fileName, string filePath, string description, string parent)
{
var fileMetadata = new File
{
Name = fileName,
MimeType = GetMimeType(fileName),
Description = description,
OriginalFilename = fileName,
};
FilesResource.CreateMediaUpload request;
using (var stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open))
{
request = service.Files.Create(fileMetadata, stream, GetMimeType(fileName));
request.Fields = "id";
request.Alt=FilesResource.CreateMediaUpload.AltEnum.Json;
request.Upload();
}
var file = request.ResponseBody;
Console.WriteLine("File ID: " + file.Id);
return null;
}
But Response body is always null and i cant upload. By the way i saw error in this picture:
google-api-dotnet-client 1.16.0.0 gzip the format of the invalid value
Anyone idea how to solve this problem and upload files google drive.
回答1:
It appears V3 has replaced InsertMediaUpload for CreateMediaUpload and when using a service account at least the ResponseBody will always be returned as NULL.
This makes it difficult to determine the ID of the file and later find it to modify permissions or do anything else.
来源:https://stackoverflow.com/questions/39468798/google-drive-api-v3-response-null