Search code examples
curlpython-requestsipfs

Curl request to IPFS Get API adds bytes to header of downloaded file


I have an IPFS node on an linux box. If i use:

ipfs get QmYqGwoiuw47cLhrtQ5yg1TnS6n2ekcLSZZt35gGestTuo

at command line the ipfs image (a png) is downloaded and usable.

However when i hit the equivalent endpoint using CURL:

curl --location --request POST 'http://127.0.0.1:5001/api/v0/get?arg=QmYqGwoiuw47cLhrtQ5yg1TnS6n2ekcLSZZt35gGestTuo' --output QmYqGwoiuw47cLhrtQ5yg1TnS6n2ekcLSZZt35gGestTuo

The file downloaded is identical except it has some bytes at the start of the file.

enter image description here

These appear before the �PNG identifier at the top of the file. (Appears to be the CID followed by some nullstrings then some numbers)

Is there anything i'm doing wrong in my post request to download the file correctly? As currently the files downloaded using CURL are unusable.


Solution

  • get is used to get IPFS objects:

    /api/v0/get

    Download IPFS objects.

    What you likely want is cat:

    /api/v0/cat

    Show IPFS object data.

    Example:

    curl --location --request POST 'http://127.0.0.1:5001/api/v0/cat?arg=QmYqGwoiuw47cLhrtQ5yg1TnS6n2ekcLSZZt35gGestTuo' --output QmYqGwoiuw47cLhrtQ5yg1TnS6n2ekcLSZZt35gGestTuo
    

    Header of output:

    PNG header