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.

2 Answers 2

7

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" 
    
4
  • 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 1, 2013 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, 2014 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. Feb 5, 2015 at 0: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 5, 2015 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'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.