You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PowerShell中用curl上传含特殊字符/非英文的文件?

解决PowerShell中curl.exe上传含特殊字符/非英文字母文件的问题

核心问题原因

你的文件路径包含方括号[](PowerShell会将其识别为通配符模式)和日文等非ASCII字符,直接在命令行传递时,curl.exe无法正确解析路径,导致无法读取文件。

解决方案

方案1:用变量存储路径+停止解析符号规避通配符

先将文件路径存入变量,再通过--%符号让PowerShell直接把参数原封不动传递给curl.exe,避免方括号被当作通配符解析:

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
$filePath = 'C:\Users\Administrator\Desktop\OST\Complete\[2026.05.25] 学園アイドルマスター 初星学園 Remix Album「ReCollection」vol.1 [FLAC 48kHz/24bit].zip'
curl.exe --% -F "sess_id=xxxxxx" -F "utype=prem" -F "to_folder=28890" -F "file_0=@$filePath" "https://d300.userdrive.org/cgi-bin/upload.cgi?upload_type=file&utype=anon"

方案2:手动转义路径中的方括号

在路径的每个方括号前加上PowerShell转义符`,明确告诉PowerShell不解析为通配符:

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
curl.exe -F "sess_id=xxxxxx" -F "utype=prem" -F "to_folder=28890" -F "file_0=@C:\Users\Administrator\Desktop\OST\Complete\`[2026.05.25`] 学園アイドルマスター 初星学園 Remix Album「ReCollection」vol.1 `[FLAC 48kHz/24bit`].zip" "https://d300.userdrive.org/cgi-bin/upload.cgi?upload_type=file&utype=anon"

方案3:用PowerShell原生命令替代curl.exe

直接使用Invoke-WebRequest(PowerShell原生的HTTP请求工具,对非ASCII路径支持更友好):

$uploadParams = @{
    Uri = "https://d300.userdrive.org/cgi-bin/upload.cgi?upload_type=file&utype=anon"
    Method = "POST"
    Form = @{
        sess_id = "xxxxxx"
        utype = "prem"
        to_folder = "28890"
        file_0 = Get-Item "C:\Users\Administrator\Desktop\OST\Complete\[2026.05.25] 学園アイドルマスター 初星学園 Remix Album「ReCollection」vol.1 [FLAC 48kHz/24bit].zip"
    }
}
Invoke-WebRequest @uploadParams

验证提示

可以先打印变量中的路径确认正确性:Write-Host $filePath,如果显示的路径和实际文件路径完全一致,说明变量存储没有问题。

内容的提问来源于stack exchange,提问作者TravelWhere

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.02 05:22:27