我有一个名为config.json
的文件,其mimeType:application/octet-stream
。
Google API Explorer - Get File Metatadatas
GET https://www.googleapis.com/drive/v3/files/1b95F40yMjPYhdZjn8zZPr6P3wjUnxoM2
和回复:
{
"kind": "drive#file",
"id": "1b95F40yMjPYhdZjn8zZPr6P3wjUnxoM2",
"name": "config.json",
"mimeType": "application/octet-stream"
}
我想将其更改为application/json
。
Google API Explorer - Change File Metatadatas
PATCH https://www.googleapis.com/drive/v3/files/1b95F40yMjPYhdZjn8zZPr6P3wjUnxoM2
{
"mimeType": "application/json"
}
但是mimeType没有改变...
{
"kind": "drive#file",
"id": "1b95F40yMjPYhdZjn8zZPr6P3wjUnxoM2",
"name": "config.json",
"mimeType": "application/octet-stream"
}
有什么建议吗?
谢谢。
同样在我的环境中,无法通过drive.files.update
更改mimeType。所以我总是使用这种解决方法。尽管我不确定这对您是否有用,但是如何呢?
drive.files.copy
端点如下。
POST https://www.googleapis.com/drive/v3/files/### file ID ###/copy
请求正文如下。
{
"mimeType": "application/json",
"name": "samplename.json"
}
如果这对您没有用,对不起。
首先,确认fileId1
的mimeType。顺便说一下,作为一个示例情况,该文件是PNG文件。我通过将mimeType更改为application/octet-stream
来上传此文件。这用作示例文件。
curl \
'https://www.googleapis.com/drive/v3/files/fileId1 \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
结果:{
"kind": "drive#file",
"id": "###",
"name": "samplefile",
"mimeType": "application/octet-stream"
}
fileId1
的文件具有application/octet-stream
的mimeType。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
结果:{
"kind": "drive#file",
"id": "fileId2",
"name": "samplename.json",
"mimeType": "application/json"
}
fileId1
的文件运行上述curl命令时,已将mimeType从application/octet-stream
更改为application/json
。有3个要点。
application/octet-stream
的mimeType更改为application/json
。这个答案是为了实现这一目标。请注意这一点。例如,当excel文件的mimeType(application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
和application/vnd.ms-excel
)可以转换为Google Spreadsheet(application/vnd.google-apps.spreadsheet
)时。但是图像文件不能直接转换为Google Spreadsheet。
来自it doesn't work for me. looks like the mimeType property is not working.
,我不了解it doesn't work for me. looks like the mimeType property is not working.
的情况。因此,如果要将Mahdi Abdi以外的mimeType更改为application/octet-stream
以外的mimeType,则可能无法使用此答案。因此,请注意这一点。