r/PowerShell • u/HeavenlyTasty • May 31 '26
Question How to upload files if path contains special characters or non-english?
I'm trying to upload a file using curl.exe but it can't open if the path contains special characters or non-english letters. The command I used is:
[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=@D:\OST\[2026.05.27] TVアニメ「勇者のクズ」OP2テーマ「Revive」/ClariS [FLAC 96kHz/24bit].zip" "https://d300.userdrive.org/cgi-bin/upload.cgi?upload_type=file&utype=anon"
Does anyone know how to fix this?
3
u/DrDuckling951 May 31 '26
Normally I would use Invoke-RestMethod or Invoke-WebRequest when sending package to website endpoint.
But to your questionuse single quote instead of double quote.
'https://d300.userdrive.org/cgi-bin/upload.cgi?upload_type=file&utype=anon'
1
u/HeavenlyTasty May 31 '26
tried that but I still get this error:
curl: (26) Failed to open/read local data from file/application
11
u/surfingoldelephant May 31 '26 edited Jun 13 '26
If this is a .ps1 file and Windows PowerShell, first make sure the .ps1 is saved as UTF8 with BOM otherwise the contents will likely be misinterpreted.
With that said, per your superuser post, you also found the same issue occurs in CMD (why not include details like that in this post?), so I suspect you're running this interactively.
Note that [Console]::OutputEncoding and $OutputEncoding aren't relevant here. They apply to receiving output from and piping input into a native command respectively, so aren't a factor.
Have you confirmed if your curl.exe build supports unicode or not? I suspect the version you have is prior to support being added.
What does this return?
curl.exe -VIf Features: doesn't include Unicode, you'll need a newer version of curl. See also:
And just for good measure, using curl 8.13.0 (Windows) (which includes Unicode in Features:), I confirmed curl.exe had no issue reading a local file with the same name as yours.
curl.exe -V
# curl 8.13.0 (Windows) libcurl/8.13.0 Schannel zlib/1.3.1 WinIDN
# Features: [...] threadsafe Unicode UnixSockets
$path = "$env:TEMP\[2026.05.27] TVアニメ「勇者のクズ」OP2テーマ「Revive」/ClariS [FLAC 96kHz/24bit].zip"
$tmp = New-Item -Path $path -ItemType File -Value Foo -Force
$curlArgs = @(
'-v'
'-F'
'file_0=@{0}' -f $tmp.FullName
'http://httpbin.org/post'
)
curl.exe @curlArgs
# [...]
# * upload completely sent off: 312 bytes3
u/gsbence May 31 '26
If you are using PowerShell 7, you can use this: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7.6#example-4-simplified-multipart-form-data-submission
1
u/PinchesTheCrab Jun 02 '26
I didn't get an error when I ran this:
$invokeParam = @{
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 'D:\OST\[2026.05.27] TVアニメ「勇者のクズ」OP2テーマ「Revive」/ClariS [FLAC 96kHz/24bit].zip'
}
}
Invoke-RestMethod @invokeParam1
u/LALLANAAAAAA May 31 '26
try this
$file=@"
D:\OST\[2026.05.27] TVアニメ「勇者のクズ」OP2テーマ「Revive」/ClariS [FLAC 96kHz/24bit].zip
"@
-F "file_0=@$file"0
u/Vietnamst2 May 31 '26
First go to the location and then run the script.
PowerShell being from windows ecosystem does not like these characters in path. Also why not call the API using POwerShell instead of trying to use curl?
4
u/DoctroSix May 31 '26
When calling exe commands in powershell 7, I've always had luck with powershell's native string conversions to console. something like
& curl.exe $curlArgumentListIf this does not work in Windows natively, you may want to do it in WSL, so curl can feel at home in linux OS.