6

How can I upload a file named yes, this filename has a comma.txt with the cli curl?

You would normally do this to upload a file with curl:

curl --progress-bar -F "fileUpload=@filename.txt"

However curl interprets commas as multiple files to upload, so this will not work:

curl --progress-bar -F "fileUpload=@yes, this filename has a comma.txt"

How can I escape the filename?


I already found a workaround by creating a temporary symlink to the original file and pass that to curl. However the problem is that the filename that curl sends to the server is the filename of the symlink, not the original file.

Tyilo
  • 2,725
  • 9
  • 40
  • 59

2 Answers2

9

You have not said what OS you are using. The following solutions work for Linux (not only for curl but most kinds of escaping):

  • Put the file name in quotes (you need to escape them as well):

      curl --progress-bar -F "fileUpload=@\"yes, this filename has a comma.txt\"" 
    
  • Escape the comma

      curl --progress-bar -F "fileUpload=@yes\, this filename has a comma.txt" 
    
terdon
  • 52,568
  • 14
  • 124
  • 170
  • I'm using Mac OS X 10.8.2, only the quoting worked. The one where the comma is escaped, tries to upload a file called "yes" (`curl: (26) couldn't open file "yes\"`). – Tyilo May 01 '13 at 16:56
  • 1
    On Mac OSX 10.9.4, I had to put the quotes after the `@` like so: `curl --progress-bar -F "fileUpload=@\"yes, this filename has a comma.txt\""` – spyle Sep 23 '14 at 17:00
  • Had same problem as spyle on Ubuntu 14.04. Terdon's answer actually sends the literal filename instead of the contents of the file. – Cory R. King Feb 05 '15 at 00:49
  • @CoryR.King yes, of course, that's intentional. How else would it work? To send the file's contents, you would need to specify a remote file name to write to. – terdon Feb 05 '15 at 13:30
0

This worked for me. The apk file has spaces in it.

#!/bin/bash
 
API_TOKEN="____"

ARTIFACT_PATH=$(find $2 -name *.ipa -o -name *.apk)

curl https://upload.diawi.com/ \
-F token=${API_TOKEN} \
-F file=@"${ARTIFACT_PATH}" \
-F callback_emails='example@gmail.com'