![](/img/trans.png)
[英]SharePoint Large Upload using MS Graph API - Erroring on second chunk
[英]Upload large file to SharePoint Online using Graph API - ContentType error
我正在寻找一种使用 PowerShell 和 Graph API 将大文件(超过 4MB)上传到 SharePoint Online 的方法。 我可以毫无问题地上传 <4MB 的文件,但我在处理更大的文件时遇到了困难。
我正在尝试使用此解决方案,但以下部分(第 105 行,尝试上传文件时)对我不起作用:
$invokeRestMethodParams = @{
Uri = $uploadUrl
Method = "PUT"
Headers = @{
Accept = "application/json"
"Content-Type" = "text/plain"
Authorization = "bearer $($token)"
"Content-Length" = $fileLength
"Content-Range" = "bytes 0-$($fileLength-1)/$($fileLength)"
}
Body = $fileInAscii
}
$response = Invoke-RestMethod @invokeRestMethodParams
我在Invoke-RestMethod上不断收到以下错误(之前的一切都很好):
The cmdlet cannot run because the -ContentType parameter is not a valid Content-Type header. Specify a valid Content-Type for -ContentType, then retry. To suppress header validation, supply the -SkipHeaderValidation parameter.
如果我使用-SkipHeaderValidation参数,我会收到以下错误:
Response status code does not indicate success: 400 (Bad Request).
我尝试过不同类型的文件(它们都小于 10MB),比如 TXT 或 PDF,甚至不同的 ContentType,比如“application/octet-stream”或“text/plain”,但似乎没有任何效果......我我还尝试了我在网上找到的另一种解决方案( 这个),但错误是一样的。
是否有其他人遇到相同的情况,或者您是否有使用 PowerShell 和 Graph API 将大文件(超过 4MB)上传到 SharePoint Online 的脚本? 太感谢了!
问候,努诺
我设法找到了一个更简单的解决方案,适用于超过 3MB 的文件(我还测试了 100MB 大小的文件)。 为了获取上传 URL,我在第一篇文章中使用了解决方案中的代码。
$fileInBytes = [System.IO.File]::ReadAllBytes($file)
$fileLength = $fileInBytes.Length
$invokeRestMethodParams = @{
Uri = $uploadUrl
Method = "PUT"
Body = $fileInBytes
Headers = @{
'Content-Range' = "bytes 0-$($fileLength-1)/$fileLength"
}
}
Try {
$response = Invoke-RestMethod @invokeRestMethodParams -ErrorAction Stop
Write-Log -Type "INF" -Message "File uploaded to SharePoint Online: '$fileName' ($([Math]::Round($file.length/1MB, 0))MB)"
} Catch {
Write-Log -Type "ERR" -Message "Unable to upload '$fileName' to SharePoint Online: '$($_.Exception.Message)'"
}
你知道我应该怎么做才能摆脱这个错误:使用“0”参数调用“ExecuteQuery”的异常:“无法从传输连接读取数据:现有连接被远程强制关闭主持人。”
我正在上传文件也是 10GB 大.. 通常在 5GB 后遇到上述错误......知道吗? 我还遇到了可能与我们公司 VPN 相关的问题。我已经包含了如下命令:[System.Threading.Timeout]::Infinite [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Ty任何帮助..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.