I'm trying to upload a file with japanese characters in the filename to a server with the following command. This works totally fine on mac or in postman, but not on Windows. Alphanumeric filenames are working.
curl -X PUT "https://api.example.com/media/test/test.mp3" -H "Content-Type: audio/mpeg" --data-binary "@/C:/Users/user1/AppData/Local/Temp/ぁ.mp3"
I get the following error message
Warning: Couldn't read data from file
Warning: "/C:/Users/user1/AppData/Local/Temp/?.mp3", this makes an empty
Warning: POST.
Is there a way to get this to work on Windows too? I tried --data-urlencode instead of --data-binary with the same result.
CodePudding user response:
Windows' command prompt is notorious for being a pain when it comes to Unicode. As a workaround: avoid using non-ASCII filenames. Usually your filename is stored along with an alternative one:
Start a command prompt (
cmd.exe
).List your file with the Unicode filename:
- First type in the path (
dir M:\folder\sub\here\
) and then either use your Tab key to iterate filenames until your wanted one appears (it will be displayed as?.txt
tho), or complete the command by adding a wildcard (i.e.*.txt
). Then run this command (hit Enter). - If you achieved that successfully do the same by adding the
/x
parameter:dir /x M:\folder\sub\here\*.txt
and you should see something like:
In the output you notice2021-09-16 11:59 <DIR> . 2021-09-16 11:59 <DIR> .. 2021-08-30 14:11 8'589'934'592 pagefile.sys 2021-09-16 11:58 4'120'885 D763~1.MP3 ?.mp3
4'120'885
as the filesize and?.mp3
as what should beぁ.mp3
. The alternative filename isD763~1.MP3
and that's what is ASCII and can be used anywhere.
- First type in the path (
Accordingly execute cURL then as:
curl -X PUT "https://api.example.com/media/test/test.mp3" -H "Content-Type: audio/mpeg" --data-binary "@/C:/Users/user1/AppData/Local/Temp/D763~1.MP3"
Again: this is the command prompt. If you'd start cURL in other ways (i.e. Win R or in a program thru CreateProcessW()
) you wouldn't have problems to begin with.