I’m trying to POST an uploaded image to IPFS via the Infura endpoint. I’ve tried multiple different ways of attacking this but I think the issue comes back to the way files are saved in Bubble. Is there a way to POST a file to an API?
I was able to successfully POST the file with Postman using a form-data body. This was the response
{
“Name”: “white_sneaker.jpg”,
“Hash”: “QmYZmAxWUxTmmjAn5oSybB5LMLtzn7mCLv8MC3Ax8xUuJS”,
“Size”: “40070”
}
Error Message Error: ENOENT: no such file or directory, open 'https://s3.amazonaws.com/appforest_uf/<id>/white_sneaker.jpg' at Object.openSync (fs.js:498:3) at Object.readFileSync (fs.js:394:35) at eval (eval at build_function (/var/task/index.js:53:12), <anonymous>:12:26) at /var/task/index.js:519:17 at run_fn (/var/task/u.js:645:18)
I assume you are working on a server side action in a plugin.
The fs module is intended for interacting with the file system. readFileSync supports URL but only with the file:// protocol.
From the error it looks like you are trying to read https://s3.amazonaws.com/appforest_uf/<id>/white_sneaker.jpg, that is not a file in the file system.
If you need to fetch remote resources you need to use context.request or another library.
Got it. Is there any documentation on how to use context.request? I’m new to javascript and trying to pull together code from what I’ve been reading online.
const { statusCode, statusMessage, body } = context.request(
"https://example.com",
{
method: "GET", // your method here
headers: {
//your headers here
},
}
);
The editor says they are using a node request, the current version used for bubble backend actions is 14, so you can find more documentation here HTTP | Node.js v14.21.2 Documentation
Do you know why I would get an Unauthorized response when using the code provide versus a successful response when using Postman with the same credentials?
I did and still getting the same error. I ended up just using the API connector for now since that’s basically what I’m trying to do. I’ll share what I did for others that want to post to IPFS.
I used the Bubble API Connector plugin to post a file to IPFS via the Infura endpoint. On the left hand side I clicked Add another API and filled in the details below. Set the POST to an Action so you can use it in a workflow.
I tried using auth with user:password and still got an error project id required. I might return to this at a different date, but I will stick with the API Connector for now.