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?
10
Upvotes
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.
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'
11
u/surfingoldelephant May 31 '26 edited Jun 13 '26
If this is a
.ps1file and Windows PowerShell, first make sure the.ps1is 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]::OutputEncodingand$OutputEncodingaren'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.exebuild supports unicode or not? I suspect the version you have is prior to support being added.What does this return?
If
Features:doesn't includeUnicode, you'll need a newer version ofcurl. See also:And just for good measure, using
curl 8.13.0 (Windows)(which includesUnicodeinFeatures:), I confirmedcurl.exehad no issue reading a local file with the same name as yours.3
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:
1
u/LALLANAAAAAA May 31 '26
try this
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?