1

I want to execute a curl command in Applescript that does the following (per this SE question/answer):

https://superuser.com/a/1054803/471181

...Do an HTTP POST of the contents (as a string) of a local file located at path/to/my-file.txt to a URL endpoint at http://example.com/API.

The correct curl command for that is the following:

Terminal
curl -d "data=@~/path/to/my-file.txt" https://example.com/API

Following the answers in this post, I tried the following Applescript command:

AppleScript
do shell script "curl -d data=@~/path/to/my-file.txt https://example.com/API"

The result I expect is to see the contents of my-file.txt POSTed to the API endpoint at https://example.com/API with the key data.

However, the actual result I see at the endpoint with the key data is the following string:

API.data
"@~/path/to/my-file.txt

In other words, instead of POSTing the contents of the file, it's POSTing the literal path to the file as a string.

Question

What is the correct Applescript command syntax?

Other unsuccessful attempts:

AppleScript
do shell script "curl -d data=\@~/path/to/my-file.txt https://example.com/API"
do shell script "curl -d \"data=@~/path/to/my-file.txt\" https://example.com/API"
do shell script "curl -d 'data=@~/path/to/my-file.txt' https://example.com/API"

On list to try:

  1. Use the fully qualified pathname to my-file.txt, do not use ~.
  2. Escape the " in the data= option, e.g.: do shell script "curl -d \"data=@~/path/to/my-file.txt\" https://example.com/API"
  • @klanomath: That gets the same result. – Mowzer Mar 22 '16 at 19:23
  • Would example.com/API really work or is it just an example? or do you have a test api somewhere? – klanomath Mar 22 '16 at 19:31
  • Two thing I can think of. 1. Use the fully qualified pathname to my-file.txt, do not use ~. 2. Escape the " in the data= option, e.g.: do shell script "curl -d \"data=@~/path/to/my-file.txt\" https://example.com/API" – user3439894 Mar 22 '16 at 20:19

You must log in to answer this question.

Browse other questions tagged .