【问题标题】:Curl failed to upload fileCurl 上传文件失败
【发布时间】:2020-01-20 10:30:29
【问题描述】:

我参考这个帖子Using curl to upload POST data with files和这个answer来上传文件。

在 Windows 上,

curl -F "file=@‪/c/Users/lf/Desktop/HQ/README" https://example.com/upload
curl: (26) Failed to open/read local data from file/application

还有 curl 版本,

curl -V
curl 7.65.3 (x86_64-w64-mingw32) libcurl/7.65.3 OpenSSL/1.1.1c (Schannel) zlib/1.2.11 libidn2/2.2.0 nghttp2/1.39.1
Release-Date: 2019-07-19
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smtp smtps telnet tftp
Features: AsynchDNS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz Metalink MultiSSL NTLM SPNEGO SSL SSPI TLS-SRP

在 Centos 上,(我也尝试使用 sudo 没有成功)

curl -F "file=@‪/data/HQ/README" https://example.com/upload
curl: (26) couldn't open file "‪/data/HQ/README"

还有 curl 版本,

curl -V
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.36 zlib/1.2.7 libidn/1.28 libssh2/1.4.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets

【问题讨论】:

  • 您要么没有权限,要么路径错误。这就是错误所说的。
  • @DieterKräutl 我使用 sudo,并且可以 vim 文件。
  • 当我删除=时,curl -F "file@‪/c/Users/lf/Desktop/HQEADME" https://example.com/upload Warning: Illegally formatted input field! curl: option -F: is badly used here curl: try 'curl --help' or 'curl --manual' for more information

标签: php forms file curl file-upload


【解决方案1】:

试试下面的方法:

curl -i -X POST -H "Content-Type: multipart/form-data" \
-F "data=@‪/data/HQ/README" http://example.com/upload

【讨论】:

猜你喜欢
  • 2017-07-07
  • 2012-02-25
  • 1970-01-01
  • 1970-01-01
  • 2013-06-09
  • 2012-03-18
相关资源
最近更新 更多