Tyi*_*ilo 6 upload curl escape-characters escaping
如何上传以yes, this filename has a comma.txtcli命名的文件curl?
您通常会这样做来上传文件curl:
curl --progress-bar -F "fileUpload=@filename.txt"
Run Code Online (Sandbox Code Playgroud)
但是curl将逗号解释为要上传的多个文件,因此这不起作用:
curl --progress-bar -F "fileUpload=@yes, this filename has a comma.txt"
Run Code Online (Sandbox Code Playgroud)
如何转义文件名?
我已经找到了一种解决方法,即创建指向原始文件的临时符号链接并将其传递给 curl。然而问题是curl发送到服务器的文件名是符号链接的文件名,而不是原始文件。
你没有说你使用的是什么操作系统。以下解决方案适用于 Linux(不仅适用于curl大多数类型的转义:
将文件名放在引号中(您也需要对它们进行转义):
curl --progress-bar -F "fileUpload=@\"yes, this filename has a comma.txt\""
Run Code Online (Sandbox Code Playgroud)转义逗号
curl --progress-bar -F "fileUpload=@yes\, this filename has a comma.txt"
Run Code Online (Sandbox Code Playgroud)