I want to execute a
curl command in Applescript that does the following (per this SE question/answer):
HTTP POSTof the contents (as a string) of a local file located at
path/to/my-file.txtto a URL endpoint at
curl command for that is the following:
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
However, the actual result I see at the endpoint with the key
data is the following string:
In other words, instead of POSTing the contents of the file, it's POSTing the literal path to the file as a string.
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:
- Use the fully qualified pathname to my-file.txt, do not use ~.
- Escape the " in the data= option, e.g.: do shell script "curl -d \"data=@~/path/to/my-file.txt\" https://example.com/API"