ローカルパスを渡すのではなく、curlコマンドでバイナリファイルURLを送信する方法

ローカルパスを渡すのではなく、curlコマンドでバイナリファイルURLを送信する方法

s3バケットのバイナリ.apkファイルをPOST APIに公開しようとしています。

私が知っているローカル方法は次のとおりです。

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

しかし、

以下を試しても機能しません。

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

私はエラーの下にいます。

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.

ベストアンサー1

@ここで何が起こっているのかは、あなたがこのオプションを乱用しているということです--data-binary。 forは使い方を非常にman page明確に説明しています。curl

データを文字で始める場合、残りは@データを読み取るファイル名、またはデータを読み取る-ファイル名でなければなりません。curl標準入力

あなたが書いた内容curl文書app-debug.apkサブディレクトリから呼び出されますexample.com

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

その後、ファイルが見つからないというメッセージが表示されますが、残りのコマンドを完了して結果が空になります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.

@URIを参照するために使用できることはどこにもないので、直接アーティファクトをインポートしてPOSTサーバーに送信するだけです。これらの提案のどれでも効果があります。

  1. POSTコンテンツをダウンロードしてアップロードしてください。

    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. POSTコンテンツのストリーミングとアップロード

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

おすすめ記事