Pinata cloud POST API

Did someone managed to set a flow for sending file to pinata cloud ?
I managed to use Postman to upload an image, so I copied the headers and set the msg.headers property.

msg.headers = {
 "content-type": 'multipart/form-data; boundary',
"pinata_api_key": flow.get('api-key'),
"pinata_secret_api_key": flow.get('api-key-secret')
}
return msg;

And I guessed the file should be sent in as a buffer inside msg.payload, but got a response:

Invalid request format

So I found the tutorial.
But got stuck on the boundary (in msg.headers)
Any suggestions or examples on how to accomplish pushing the stream of data?

Hi Vukmirovic,

unfortunately i dont know anything about the Pinata service but i had a quick browse through its documentation and they have something called Pinata NodeJS SDK

Looking at the code examples,
you could use the Function node's new feature of loading external libraries ( functionExternalModules )
and try to replicate the pinfiletoipfs code examples

ps. instead of using const fs = require('fs'); try to pass the data from the File read node

1 Like

Yea i tried, but without luck...

const pinata = pinataSDK('yourPinataApiKey', 'yourPinataSecretApiKey');

TypeError: pinataSDK is not a function

can you confirm that the library is indeed installed in NR node_modules.
have you tried the testAuthentication code on that page ?

const pinata = pinataSDK('yourPinataApiKey', 'yourPinataSecretApiKey');

pinata.testAuthentication().then((result) => {
    //handle successful authentication here    
    node.warn(result);
}).catch((err) => {    
  //handle error here    
    node.warn(err);
});

it seems to be working for me. i get an error reply back

image

Okay so doing basic authentication with a function node gets the same error...
Have edited the setup tab correctly.
And can confirm that in .node-red/node_modules is a @pinata folder and a subfolder sdk...

Running node-red on digital ocean as a root user.
I was trying to parse global context as api key and secret, maybe this is causing some kind of error, will edit and check again...

Edit2: Still getting the same error: PinataSDK is not a function.

[
    {
        "id": "f6c8bb8c.63c8b",
        "type": "inject",
        "z": "d8af3a19.cf979",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 140,
        "y": 560,
        "wires": [
            [
                "9a7fa24aec49c733"
            ]
        ]
    },
    {
        "id": "eb856269.cdcd78",
        "type": "debug",
        "z": "d8af3a19.cf979",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 490,
        "y": 560,
        "wires": []
    },
    {
        "id": "9a7fa24aec49c733",
        "type": "function",
        "z": "d8af3a19.cf979",
        "name": "",
        "func": "const pinata = pinataSDK('dbe7b2988967075232d6','fdc928821fa73ae6b896091a3ef0d8d02eac5a47baa1a14385c42b8302c58eb9')\npinata.testAuthentication().then((result) => {\n    //handle successful authentication here\n    console.log(result);\n}).catch((err) => {\n    //handle error here\n    console.log(err);\n});",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [
            {
                "var": "pinataSDK",
                "module": "@pinata/sdk"
            }
        ],
        "x": 300,
        "y": 560,
        "wires": [
            [
                "eb856269.cdcd78"
            ]
        ]
    }
]

Hello lizzardguki,

I can connect with your flow .. so it must something having to do with running your system with digital ocean. ( dont know how to help debug that .. we need some help from the master developers )

lets try will the traditional way of loading external libraries (functionGlobalContext)
Edit your settings.js file and look for the section of functionGlobalContext and uncomment/add

functionGlobalContext: {
    pinataSDK:require('@pinata/sdk')
}

Then from the Function node remove the entry from Setup tab (by press the X button) and add in the code
let pinataSDK= global.get('pinataSDK')

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.