0

Googleドライブアカウントに画像を挿入しているときにエラーが発生しました。コード「メディアタイプ」はサポートされていません。有効なメディアタイプ:[ / ]」をご覧ください。

private static Google.Apis.Drive.v2.Data.File insertFile(DriveService service, String title,  String description, String parentId, String mimeType, String filename)
{
    // File's metadata.
    Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
    body.Title = "Bluehills.jpg";
    body.Description = "hello";
    body.MimeType = "application/vnd.google-apps.drive-sdk";
    //var googleFile = new google.Google.Apis.Drive.v2.Data.File();

    // Set the parent folder.
    if (!String.IsNullOrEmpty(parentId))
    {
        body.Parents = new List<ParentReference>() { new ParentReference() { Id = parentId } };
    }

    // File's content.
    byte[] byteArray = System.IO.File.ReadAllBytes(filename);
    MemoryStream stream = new MemoryStream(byteArray);

    try
    {
        FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, mimeType);
        request.Upload();

        Google.Apis.Drive.v2.Data.File file = request.ResponseBody;

        // Uncomment the following line to print the File ID.
        // Console.WriteLine("File ID: " + file.Id);

        return file;
    }
    catch (Exception e)
    {
        Console.WriteLine("An error occurred: " + e.Message);
        return null;
    }
}
4

1 に答える 1

1

「application/vnd.google-apps.drive-sdk」は、ショートカットの作成に使用されます。

別の MIME タイプを使用してみてください。いいね:画像/jpeg

https://developers.google.com/drive/release-notesを参照してください

于 2012-10-19T13:31:18.273 に答える