-1

I am trying to post a binary .apk file which is on s3 bucket to a POST API.

Local way which I know is:

curl -X POST https://xxx.example.com:443/api/storage/upload -H "Content-Type:application/octet-stream" --data-binary @file_name.file

But

I when I try the following, it is not working

curl -X POST https://xxx.example.com:443/api/storage/upload -H "Content-Type:application/octet-stream" --data-binary @example.com/app-debug.apk

I am getting below Error.

Warning: Couldn't read data from file
Warning: "https://s3-eu-west-1.amazonaws.com/files.greenhouseci.com/projects/6d
Warning: 7f406a-2a65-4be0-83ee-75ca0afae7c9/builds/24f78eb5-819f-44d5-9c21-edce
Warning: 4dc9f253/artefacts/app-debug.apk", this makes an empty POST.
5
  • 3
    'It's not working' ... what are we supposed to do with this information? What is not working? What error do you get? Commented Mar 13, 2019 at 8:40
  • 3
    ... And what is it you're actually trying to do? Commented Mar 13, 2019 at 8:46
  • 1
    Welcome to the site: Can you improve the question, by telling us what you expect to happen, and what happened. Commented Mar 13, 2019 at 8:59
  • 2
    If you use the same account, then you can edit your own questions. Commented Mar 13, 2019 at 9:04
  • 2
    Is that the exact command you ran and the exact error message? Or is that you masked the actual filename from the command, but not from the error message? Commented Mar 13, 2019 at 12:55

1 Answer 1

7

What's happening here is that you're misusing the @ flag for the --data-binary option. The man page for curl describes its use quite clearly

If you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin.

What you wrote instructed curl to use the file called app-debug.apk from the subdirectory example.com:

curl ... --data-binary @example.com/app-debug.apk

It then told you that it couldn't find that file, but then proceeded to complete the rest of the command, resulting in an empty POST:

Warning: Couldn't read data from file
Warning: "https://s3-eu-west-1.amazonaws.com/files.greenhouseci.com/projects/6d
Warning: 7f406a-2a65-4be0-83ee-75ca0afae7c9/builds/24f78eb5-819f-44d5-9c21-edce
Warning: 4dc9f253/artefacts/app-debug.apk", this makes an empty POST.

Nowhere does it say that @ can be used to reference a URI, so what you need to do is to get the artifact yourself and then POST it to your server. Something like either of these suggestions could work

  1. Download the POST content and then upload it

    curl https://example.com/app-debug.apk >app-debug.apk
    curl -X POST https://xxx.example.com:443/api/storage/upload -H "Content-Type:application/octet-stream" --data-binary @app-debug.apk
    
  2. Stream the POST content and upload it

    curl https://example.com/app-debug.apk |
        curl -X POST https://xxx.example.com:443/api/storage/upload -H "Content-Type:application/octet-stream" --data-binary @-
    
2
  • How to make this work with sending data to an FTP/SFTP server? Commented Jun 1, 2023 at 16:18
  • There's no such thing, @ChrisF. You can have an FTP server such as vsftpd, which may or may not be configured to support not only FTP but also FTP/S, or you can have an SFTP server running under sshd Commented Jun 1, 2023 at 20:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.