fix: replace WebClient with curl.exe for APK upload (5min timeout)
WebClient.UploadData() has no configurable timeout and was silently timing out on 89MB uploads over Tailscale. curl.exe (built-in on Windows 10+) is used instead with --max-time 300 (5 minutes). Made-with: Cursor
This commit is contained in:
parent
2890b6cb6f
commit
7a20f161dd
|
|
@ -131,27 +131,20 @@ foreach ($apk in $apkFiles) {
|
|||
$mb = [math]::Round($apk.Length / 1MB, 1)
|
||||
Write-Host " Uploading: $($apk.Name) ($mb MB)..." -ForegroundColor Gray
|
||||
|
||||
$boundary = [System.Guid]::NewGuid().ToString()
|
||||
$uploadUrl = "$GITEA_BASE_URL/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/releases/$($release.id)/assets?name=$($apk.Name)"
|
||||
|
||||
$fileBytes = [System.IO.File]::ReadAllBytes($apk.FullName)
|
||||
$enc = [System.Text.Encoding]::UTF8
|
||||
# curl.exe (Windows 10+ 内蔵) を使用: WebClient より大容量ファイルに強く、
|
||||
# --max-time で明示的なタイムアウト設定が可能
|
||||
$curlOutput = curl.exe -s --max-time 300 `
|
||||
-X POST $uploadUrl `
|
||||
-H "Authorization: token $GITEA_TOKEN" `
|
||||
-F "attachment=@$($apk.FullName);type=application/octet-stream"
|
||||
|
||||
$bodyParts = [System.Collections.Generic.List[byte]]::new()
|
||||
$header = "--$boundary`r`nContent-Disposition: form-data; name=`"attachment`"; filename=`"$($apk.Name)`"`r`nContent-Type: application/octet-stream`r`n`r`n"
|
||||
$bodyParts.AddRange($enc.GetBytes($header))
|
||||
$bodyParts.AddRange($fileBytes)
|
||||
$footer = "`r`n--$boundary--`r`n"
|
||||
$bodyParts.AddRange($enc.GetBytes($footer))
|
||||
$bodyArray = $bodyParts.ToArray()
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "curl upload failed (exit code $LASTEXITCODE)"
|
||||
}
|
||||
|
||||
$wc = New-Object System.Net.WebClient
|
||||
$wc.Headers.Add("Authorization", "token $GITEA_TOKEN")
|
||||
$wc.Headers.Add("Content-Type", "multipart/form-data; boundary=$boundary")
|
||||
$result = $wc.UploadData($uploadUrl, "POST", $bodyArray)
|
||||
$wc.Dispose()
|
||||
|
||||
$json = [System.Text.Encoding]::UTF8.GetString($result) | ConvertFrom-Json
|
||||
$json = $curlOutput | ConvertFrom-Json
|
||||
$downloadUrls[$apk.BaseName] = $json.browser_download_url
|
||||
Write-Host " OK: $($json.browser_download_url)" -ForegroundColor Green
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue