I have a file named config.json
with the mimeType: application/octet-stream
.
Google API Explorer - Get File Metatadatas
GET https://www.googleapis.com/drive/v3/files/1b95F40yMjPYhdZjn8zZPr6P3wjUnxoM2
and the response:
{
"kind": "drive#file",
"id": "1b95F40yMjPYhdZjn8zZPr6P3wjUnxoM2",
"name": "config.json",
"mimeType": "application/octet-stream"
}
I want to change it to application/json
.
Google API Explorer - Change File Metatadatas
PATCH https://www.googleapis.com/drive/v3/files/1b95F40yMjPYhdZjn8zZPr6P3wjUnxoM2
{
"mimeType": "application/json"
}
But the mimeType didn't change...
{
"kind": "drive#file",
"id": "1b95F40yMjPYhdZjn8zZPr6P3wjUnxoM2",
"name": "config.json",
"mimeType": "application/octet-stream"
}
Any suggestions ?
Thank you.
Also in my environment, the mimeType cannot be changed by drive.files.update
. So I always use this workaround. Although I'm not sure whether this is useful for you, how about this?
drive.files.copy
Endpoint is as follows.
POST https://www.googleapis.com/drive/v3/files/### file ID ###/copy
Request body is as follows.
{
"mimeType": "application/json",
"name": "samplename.json"
}
If this was not useful for you, I'm sorry.
At first, the mimeType of fileId1
is confirm. By the way, as a sample situation, this file is a PNG file. I uploaded this by changing the mimeType to application/octet-stream
. This is used as the sample file.
curl \
'https://www.googleapis.com/drive/v3/files/fileId1 \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
Result:
{
"kind": "drive#file",
"id": "###",
"name": "samplefile",
"mimeType": "application/octet-stream"
}
fileId1
has the mimeType of application/octet-stream
.curl --request POST \
'https://www.googleapis.com/drive/v3/files/fileId1/copy \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"mimeType":"application/json","name":"samplename.json"}' \
--compressed
Result:
{
"kind": "drive#file",
"id": "fileId2",
"name": "samplename.json",
"mimeType": "application/json"
}
fileId1
, it was changed that the mimeType was changed from application/octet-stream
to application/json
.There are 3 important points.
application/octet-stream
to application/json
. This answer is for achieving this goal. Please be careful this.For example, when the mimeType of excel file (application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
and application/vnd.ms-excel
) can be converted to Google Spreadsheet (application/vnd.google-apps.spreadsheet
). But the image file cannot be directly converted to Google Spreadsheet.
From it doesn't work for me. looks like the mimeType property is not working.
, I cannot understand about Mahdi Abdi's situation. So if you want to change the mimeType except for application/octet-stream
to the mimeType except for application/json
, this answer might not be able to be used. So please be careful this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With