salman
salman

Reputation: 35

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

I am getting an error while inserting an image to my Google - drive account , please look at the code"Media type '' is not supported. Valid media types: [/]"

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;
    }
}

Upvotes: 0

Views: 1767

Answers (2)

Jatin Dave
Jatin Dave

Reputation: 852

I also found one more solution. Consumes Attribute, Either remove Consumes attribute or Add as following image. enter image description here

Upvotes: 0

animaonline
animaonline

Reputation: 3804

"application/vnd.google-apps.drive-sdk" is used for creating shortcuts.

Try using another mime type. Like: image/jpeg

See https://developers.google.com/drive/release-notes

Upvotes: 1

Related Questions