The problem appears to be including the Authorization header on the PUT request for a multipart upload. From the documentation:
Including the Authorization header when issuing the PUT
call may result in a HTTP 401 Unauthorized
response. The Authorization header and bearer token should only be sent when issuing the POST
during the first step. It should be not be included when issuing the PUT
.
From my log:
2023/10/04 22:19:11 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2023/10/04 22:19:11 DEBUG : Copy-M365UserDrive.txt: Uploading segment 0/18 size 18
2023/10/04 22:19:11 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2023/10/04 22:19:11 DEBUG : HTTP REQUEST (req 0xc000523000)
2023/10/04 22:19:11 DEBUG : PUT /personal/cd3c266076684197/_api/v2.0/drives/... HTTP/1.1
Host: my.microsoftpersonalcontent.com
User-Agent: ISV|Transend Corporation|TMCTools/1.0
Content-Length: 18
Authorization: Bearer EwC...
Content-Range: bytes 0-17/18
Accept-Encoding: gzip
2023/10/04 22:19:11 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2023/10/04 22:19:11 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2023/10/04 22:19:11 DEBUG : HTTP RESPONSE (req 0xc000523000)
2023/10/04 22:19:11 DEBUG : HTTP/2.0 401 Unauthorized