繁体   English   中英

不支持媒体类型“”。 有效的媒体类型:[*/*]

[英]Media type '' is not supported. Valid media types: [*/*]

向我的 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;
    }
}

“ application / vnd.google-apps.drive-sdk”用于创建快捷方式。

尝试使用其他mime类型。 喜欢:图片/ jpeg

请参阅https://developers.google.com/drive/release-notes

我还找到了另一种解决方案。 消耗属性,删除消耗属性或添加如下图。 在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM