I'm trying to change the mime type of a file as described in the documentation to "application/vnd.google-apps.folder"
. However when I make the web request no error is thrown but the mime type does not change.
This is my code:
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
is working correctly while set
is not. This confuses me as my Name
variable works correctly and with completely the same method only with the names swapped out.
This is the CreateRequest
method I used:
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;
}
I don't understand why you are trying to change a file's mime to a Folder's mime type (application/vnd.google-apps.folder), that's not feasible, what you can do instead if you want to change a Google Drive file mime type like for example application/vnd.google-apps.spreadsheet or application/vnd.google-apps.document, you can use the Files: export endpoint.
Passing as parameters the document id and the mimeType you want to change it, you will get as a response that same document, but in the desired mimeType.
For further knowledge in all the mime types available, check G Suite documents and corresponding export MIME types.