dvncan
June 20, 2023, 8:31pm
1
Hi, It looks like last week June 13 2023, ipfs-http-client was deprecated. This is bad because it is how I am connecting to my IPFS dedicated gateway as per this issue: Add file to ipfs (node.js) - #4 by Flaveeu
Here is my code:
const fs = require('fs');
const dotenv = require('dotenv');
dotenv.config();
//infura config
const ipfsClient = require('ipfs-http-client');
const projectId = process.env.API_KEY;
const projectSecret = process.env.API_SECRET;
const logger =require('./logger');
const axios = require('axios');
const auth = 'Basic ' + Buffer.from(projectId+':'+projectSecret).toString('base64');
const client = ipfsClient.create({
host: 'ipfs.infura.io',
port: 5001,
path: '/api/v0/add',
protocol: 'https',
headers: { authorization: auth,},
});
async function ipfsUploadFunction(folder, index, public_id){
const logs =logger.newLogger({fileName:'ipfsUpload.js',function:'ipfsUploadFunction', id:public_id});
logs.info("\n***** Configuring IPFS... *****");
try{
file = fs.readFileSync(folder + index);
let cid = await client.add(file);
console.log(`*** successful transaction: ${cid.cid.toString()} ***`);
return cid.cid.toString();
}catch(err){
logs.error("what is this error? " +err);
return ('failed');
}
};
The error I am getting is this:
TypeError: RequestInit: duplex option is required when sending a body.
If anyone has a fix for me please let me know!
@dvncan
2 Likes
hey, it might be just a Node issue see RequestInit: duplex option is required when sending a body · Issue #46221 · nodejs/node · GitHub
What node version are you using ?
As for Helia, it looks like it doesn’t support yet connecting to a remote ipfs provider but we’ll keep an eye and add tutorials when the time comes.
1 Like
dvncan
June 26, 2023, 7:08pm
3
Hey, node version is 18.12.1 and I think it is more likely because the library has been closed and made read only (on june 13 2023). Can you please verify that your solution still works as described by
> # ⛔️ DEPRECATED: [js-IPFS](https://github.com/ipfs/js-ipfs) has been superseded by [Helia](https://github.com/ipfs/helia)
>
> 📚 [Learn more about this deprecation](https://github.com/ipfs/js-ipfs/issues/4336) or [how to migrate](https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS)
>
> ⚠️ If you continue using this repo, please note that security fixes will not be provided
# ipfs-http-client <!-- omit in toc -->
[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)
[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-ipfs/test.yml?branch=master\&style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/test.yml?query=branch%3Amaster)
> A client library for the [IPFS HTTP API](https://github.com/ipfs/js-ipfs/tree/master/docs/core-api) exposed by js-ipfs.
> Note: The client library for the [Kubo RPC API](https://docs.ipfs.tech/reference/kubo/rpc/) has moved into [js-kubo-rpc-client](https://github.com/ipfs/js-kubo-rpc-client).
## Table of contents <!-- omit in toc -->
This file has been truncated. show original
1 Like
dvncan
June 26, 2023, 7:39pm
4
I found a solution which works for postman which is to use the IPFS endpoint I will outline how I configured it below.
Remove all origin restrictions… I have not had any success setting ip restrictions and it creates confusion, I wrote about it here. …
Set postman Auth to Basic Auth & API_KEY:API_SECRET
POST : https://ipfs.infura.io:5001/api/v0/add
Include the file path in the request body, I used form-data and selected the down arrow in the key section to toggle the request to file.
External Image
1 Like
dvncan
June 30, 2023, 1:41pm
5
Hey this is still an issue for me. I was getting axios object error which is described here when trying to do the call programmatically.
1 Like
dvncan
June 30, 2023, 1:53pm
6
@traian.vila I didn’t tag you in my reply but I added some context to the ticket.
1 Like
do you have any allowed origins set in your ipfs key security settings ?
1 Like
dvncan
June 30, 2023, 2:12pm
8
@traian.vila
I removed all restrictions so the key is open. it works with postman but i am getting an axios error doing it programmatically
see below:
async function ipfsPostFunction(folder, index, public_id){
const logs =logger.newLogger({fileName:'ipfsUpload.js',function:'ipfsUploadFunction', id:public_id});
logs.info("\n***** Configuring IPFS... *****");
try{
let API_KEY = process.env.API_KEY;
let API_SECRET = process.env.API_SECRET;
const projectIdAndSecret = `${API_KEY}:${API_SECRET}`
const auth = `Basic ${Buffer.from(projectIdAndSecret).toString('base64')}`
let url = 'https://ipfs.infura.io:5001/api/v0/add';
let file = `file=@".${folder}/${index}}"`
let options = {headers: {authorization: auth,'Content-Type': "multipart/form-data"},};
console.log(options);
let response = await axios.post(url, file, options );
response.on('response', function (response) {
response = JSON.parse("[" + data.split("}\n{").join("},{") + "]");
return data;
});
// console.log(response);
// console.log(`*** adding file: ${file}... ***`);
// let cid = await client.add(file);
// console.log(`*** successful transaction: ${cid.cid.toString()} ***`);
// figure out how to skip if already contained in list.
// return cid.cid.toString();
}catch(err){
logs.error("IPFS Failure: " +err);
return ('failed');
// cidList.push(err);
}
//console.log(cidList)
}
someone wrote to transform the response but I couldn’t find the exact way to do that… The error is an open bug for objects which are not proper JSON.
1 Like
@dvncan @traian.vila I am seeing the same issue as of last week. I tried the helia route, but encountered the same problem of not being able to configure Infura as a 3rd party node. Still researching possible alternatives, but hitting a dead end for now and this is a blocker for some production work that needs to be done unfortunately.
2 Likes
system
Closed
July 20, 2023, 8:32pm
10
This topic was automatically closed after 30 days. New replies are no longer allowed.