簡體   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