addFromFs doesn't include headers that are injected during api initialization
Closed this issue · 6 comments
bonedaddy commented
I'm using js-ipfs-http-client to add a directory from my local filesystem, however it appears to be ignoring authorization headers that I send via a JWT.
This is th script in question https://github.com/RTradeLtd/directory-upload/blob/master/src/index.ts
This is where I'm setting headers https://github.com/RTradeLtd/directory-upload/blob/master/src/index.ts#L49
alanshaw commented
@bonedaddy what version of the client are you using?
alanshaw commented
@bonedaddy any chance you can give #1173 a go to see if it fixes your problem?
bonedaddy commented
@alanshaw unfortunately that did not help. Here's the error message
HTTPError: Unauthorized
at errorHandler (/home/solidity/Code/RTradeLtd/directory-upload/node_modules/ipfs-http-client/src/lib/error-handler.js:41:17)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async fn (/home/solidity/Code/RTradeLtd/directory-upload/node_modules/ky/umd.js:325:31)
at async /home/solidity/Code/RTradeLtd/directory-upload/node_modules/ipfs-http-client/src/add/index.js:33:17
at async toArray (/home/solidity/Code/RTradeLtd/directory-upload/node_modules/async-iterator-all/index.js:6:20) {
name: 'HTTPError',
response: Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]: { body: [PassThrough], disturbed: true, error: null },
[Symbol(Response internals)]: {
url: 'https://api.ipfs.temporal.cloud/api/v0/add?stream-channels=true',
status: 401,
statusText: 'Unauthorized',
headers: [Headers],
counter: undefined
}
}
} HTTPError: Unauthorized
at errorHandler (/home/solidity/Code/RTradeLtd/directory-upload/node_modules/ipfs-http-client/src/lib/error-handler.js:41:17)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async fn (/home/solidity/Code/RTradeLtd/directory-upload/node_modules/ky/umd.js:325:31)
at async /home/solidity/Code/RTradeLtd/directory-upload/node_modules/ipfs-http-client/src/add/index.js:33:17
at async toArray (/home/solidity/Code/RTradeLtd/directory-upload/node_modules/async-iterator-all/index.js:6:20)
alanshaw commented
@bonedaddy I just tried using this test script:
const http = require('http')
const ipfsClient = require('./')
async function main () {
const server = http.createServer((req, res) => {
console.log(req.headers) // <--- logging out the sent headers
res.write(JSON.stringify({
path: 'package.json',
hash: 'QmdDMgC4Q7L5dkJZKNXM4o4DcvpDccV5V98AEBKopddwQP',
size: 7281
}))
res.end()
})
await server.listen(3000)
const ipfs = ipfsClient({
port: 3000,
headers: {
authorization: 'foobar'
}
})
const res = await ipfs.addFromFs('./package.json')
console.log(res)
}
main()...and got the response:
{
authorization: 'foobar',
'content-type': 'multipart/form-data;boundary=--------------------------615041762026629165077897',
accept: '*/*',
'user-agent': 'node-fetch/1.0 (+https://github.com/bitinn/node-fetch)',
'accept-encoding': 'gzip,deflate',
connection: 'close',
host: 'localhost:3000',
'transfer-encoding': 'chunked'
}
[
{
path: undefined,
hash: 'QmdDMgC4Q7L5dkJZKNXM4o4DcvpDccV5V98AEBKopddwQP',
size: 7281
}
]
Are you sure you have a valid JWT?