This repository was archived by the owner on Mar 10, 2020. It is now read-only.
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
ipfs.files.add(Buffer) > TypeError: content.once is not a function #649
Closed
Description
Hello, I'm using the ipfs-js-api and am having a problem with ipfs.files.add()
when adding a Buffer.
I'm following the this usage example from js-ipfs-api/examples/name-api/index.js
:
let buffer = Buffer.from(input.value)
ipfs.add(buffer)
.then(res => {
publish(res[0].path)
input.value = ''
})
.catch(err => {
showStatus('failed to add the data', COLORS.error)
console.error(err)
})
}
This is my code:
var Promise = require('promise')
var Buffer = require('buffer/').Buffer
var ipfsAPI = require('ipfs-api')
var ipfs = ipfsAPI('/ip4/127.0.0.1/tcp/5001')
var myBuffer = Buffer.from('hello')
ipfs.files.add(myBuffer, function (err, result) {
if (err) {
console.log(err)
} else {
console.log(result[0].hash)
}
})
And I'm getting this output (in Node.js):
Error: "files" must be a buffer, readable stream, or array of objects
In the browser, I can solve the problem by putting the Buffer inside an array (I don't know why that solves it though...):
ipfs.files.add([myBuffer], function (err, result) {
But in Node.js I get this error:
TypeError: content.once is not a function
at Multipart._pushFile ($proj/src/node_modules/ipfs-api/src/utils/multipart.js:80:13)
at Multipart._maybeDrain ($proj/src/node_modules/ipfs-api/src/utils/multipart.js:48:14)
at Multipart._transform ($proj/src/node_modules/ipfs-api/src/utils/multipart.js:40:10)
at Multipart.Transform._read (_stream_transform.js:167:10)
at Multipart.Transform._write (_stream_transform.js:155:12)
at doWrite (_stream_writable.js:307:12)
at writeOrBuffer (_stream_writable.js:293:5)
at Multipart.Writable.write (_stream_writable.js:220:11)
at eachSeries ($proj/src/node_modules/ipfs-api/src/utils/send-files-stream.js:52:35)
at $proj/src/node_modules/async/internal/withoutIndex.js:9:16
Does anyone have any idea why this happens?
Thanks :)
Metadata
Metadata
Assignees
Labels
No labels