2

I refer to this post Using curl to upload POST data with files and this answer to upload files.

On 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

and the curl version,

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

On Centos, (I also try with sudo without success)

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

and the curl version,

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
LF00
  • 27,015
  • 29
  • 156
  • 295
  • You either have no permissions or the path is wrong. Thats what the error sais. – Dieter Kräutl Sep 19 '19 at 11:40
  • @DieterKräutl I use sudo, and can vim the file. – LF00 Sep 19 '19 at 11:40
  • When remove the `=` I get, `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 ` – LF00 Sep 19 '19 at 11:44
  • https://www.dorcode.com/questions/134/how-to-post-file-or-image-using-php-curl – PHP Ninja Sep 19 '19 at 11:51

1 Answers1

2

Try it the following way:

curl -i -X POST -H "Content-Type: multipart/form-data" \
-F "data=@‪/data/HQ/README" http://example.com/upload
LF00
  • 27,015
  • 29
  • 156
  • 295
Dieter Kräutl
  • 657
  • 4
  • 8
  • 1
    I finally find it's "@‪" cause the problem. Refer to [ord, md5 shows different behaviour on @](https://stackoverflow.com/a/58010740/6521116) – LF00 Nov 20 '19 at 01:49