无法更改文件的哑剧类型

问题描述 投票:0回答:1

我正在尝试将文件的模仿类型如in the documentation更改为"application/vnd.google-apps.folder"。但是,当我发出Web请求时,不会引发任何错误,但mime类型不会改变。

这是我的代码:

public string MimeType
{
    get
    {
        dynamic data = JsonConvert.DeserializeObject(JsonMetadata); //the json of the fileID
        return data.mimeType;
    }
    set
    {
        RandomMethods.CreateRequest( //custom method for creating HttpWebRequest
            "PATCH", //method
            string.Format("https://www.googleapis.com/drive/v3/files/{0}?access_token={1}", FileID, Auth.AccessToken), //url
            "application/json", //content type
            "{ \"mimeType\": \"" + value + "\"}" //body
        ).GetResponse().Dispose();
    }
}

[get正常工作,而set无效。这使我感到困惑,因为我的Name变量可以正常工作,并且只有换了名字才使用完全相同的方法。

这是我使用的CreateRequest方法:

public static HttpWebRequest CreateRequest(string method, string url, string contentType, string body)
{
    var req = WebRequest.Create(url) as HttpWebRequest;
    req.Method = method;
    req.ContentType = contentType;
    byte[] data = Encoding.UTF8.GetBytes(body);
    req.ContentLength = data.Length;
    using (Stream stream = req.GetRequestStream())
        stream.Write(data, 0, data.Length);
    return req;
}
c# google-api google-drive-api httpwebrequest mime-types
1个回答
0
投票

我不明白为什么您要尝试将文件的mime更改为文件夹的mime类型(application / vnd.google-apps.folder),这是不可行的,如果您想更改Google Drive文件的MIME类型,例如application / vnd.google-apps.spreadsheetapplication / vnd.google-apps.document,您可以使用Files: export终结点。

enter image description here

将要更改的文档ID和mimeType作为参数传递,您将获得相同的文档作为响应,但使用所需的mimeType。

有关要获得的所有所有哑剧类型的进一步知识,请选中G Suite documents and corresponding export MIME types

© www.soinside.com 2019 - 2024. All rights reserved.