【发布时间】:2017-01-10 15:26:58
【问题描述】:
我能够从 google drive api 下载文件,但是,它只适用于文本文件。
如何下载其他类型的文件?
示例:word 文件已下载,但当我打开它时,我得到了
“很抱歉,我们无法打开文件,因为我们发现文件内容有问题”
这是代码。谢谢。
function getfile($uri){
$results = Invoke-RestMethod `
-Method GET `
-Uri $uri `
-Headers @{Authorization = Get-Token} `
-ContentType application/json
return $results
}
$fileId = "word document id"
$fileproperties = getfile -uri "https://www.googleapis.com/drive/v3/files/$fileId"
$actualfile = getfile -uri "https://www.googleapis.com/drive/v3/files/$($fileId)?alt=media"
$actualfile | out-file c:..\Desktop\$($fileproperties.name)
【问题讨论】:
-
您的
getfile函数为所有请求返回 json 内容类型。这是基于文本的。如果您尝试以 json 格式返回 word 文档,则返回的内容可能已损坏。我建议将内容类型设为函数参数,以便在下载媒体时指定正确的 mime 类型
标签: powershell google-drive-api