ipfs / go-ipfs-http-client

[archived] Legacy Kubo RPC client, use kubo/client/rpc instead.
MIT License
109 stars 41 forks source link

Using Data ObjectAPI results in invalid Character during parsing of object #150

Closed cycorax12 closed 3 years ago

cycorax12 commented 3 years ago

I am using infura go-ipfs-http-client to get data for given path. I get data, but when unmarshalling json to Struct it fails with below error

panic: invalid character '\b' looking for beginning of value

Code:

//content := strings.NewReader("Infura IPFS - Getting started demo.")
    mypath := path.New("Qmb5zeyvU7ZpotLDzkUmSeMDA71MExp8eJyNeefGdoeA2x/2")
    reader, err := httpApi.Object().Data(context.Background(), mypath)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    var nftData NFTTraitData
    data, _ := ioutil.ReadAll(reader)

    err1 := json.Unmarshal([]byte(data), &nftData)
    if err1 != nil {
        panic(err1)
    }

Response received in "data" field

☻↕�♣{"name":"Obit #2","description":"AN 8-BIT OBITUARY OF FAMILY FIENDS\n\nThere are 7,132 Obits. We are all unique, restless souls of our own generation. Dead Ringers are the most coveted of the clan but ownership of any Obit will grant you access to exclusive launches, airdrops, and other surprising pleasures. Grave pleasures indeed.\n\nVisit the [Obits website](https://obitsnft.com) for more details.","background_color":"cccccc","image":"ipfs://QmPASmu4tqbgwuceqWtHbEZTrn24zsva1NDBxpfzEjVpQR/2.png","external_url":"https://obitsnft.com","attributes":[{"trait_type":"type","value":"Female"},{"trait_type":"Accessory","value":"Black Side"},{"trait_type":"Accessory","value":"Cigar"},{"trait_type":"Lived","value":"1999 - 2018"}]}↑�♣

Do we need to perform some decoding etc?

welcome[bot] commented 3 years ago

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review. In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment. Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

Finally, remember to use https://discuss.ipfs.io if you just need general support.

Stebalien commented 3 years ago

It looks like you've stored a JSON file in IPFS as a file. You need to read it as a file with https://pkg.go.dev/github.com/ipfs/go-ipfs-http-client#HttpApi.Unixfs.

Specifically, api.Unixfs().Get(ctx, path).