-2

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.
  • 3
    'It's not working' ... what are we supposed to do with this information? What is not working? What error do you get? – Panki Mar 13 at 8:40
  • 3
    ... And what is it you're actually trying to do? – roaima Mar 13 at 8:46
  • 1
    Welcome to the site: Can you improve the question, by telling us what you expect to happen, and what happened. – ctrl-alt-delor Mar 13 at 8:59
  • 1
    If you use the same account, then you can edit your own questions. – ctrl-alt-delor Mar 13 at 9:04
  • 1
    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? – ilkkachu Mar 13 at 12:55
2

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 @-
    

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.