Expected data to be a string, Uint8Array or ArrayBuffer
See original GitHub issueWhen attempting to upload a file to arlocal
in node.js I get the following error
Error: Expected data to be a string, Uint8Array or ArrayBuffer
It looks like I am passing an ArrayBuffer:
const Arweave = require('arweave')
const arweave = Arweave.init({
host: '127.0.0.1',
port: 1984,
protocol: 'http',
})
async function createTransaction(arrayBuffer: ArrayBuffer) {
if (!arrayBuffer) return
try {
// generate test wallet
const key = await arweave.wallets.generate()
/* creates and sends transaction to Arweave */
const transaction = await arweave.createTransaction({ data: arrayBuffer }, key)
await arweave.transactions.sign(transaction, key)
const uploader = await arweave.transactions.getUploader(transaction)
/* upload indicator */
while (!uploader.isComplete) {
//
await uploader.uploadChunk()
}
return transaction.id
} catch (err) {
console.log('createTransaction error: ', (err))
}
}
const file = await admin.storage().bucket('my-bucket').file(filePath).download();
// typecast to Array Buffer
const ab = file as unknown as ArrayBuffer;
const id = await createTransaction(ab)
What am I doing wrong?
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Uint8Array to string in Javascript - Stack Overflow
You can convert a Node.js Buffer to a JavaScript string using buffer.toString("utf8", start, end) where end = start + length ...
Read more >Uint8Array - JavaScript - MDN Web Docs
Chrome Edge
Uint8Array Full support. Chrome7. Toggle history Full support. Edge12...
Uint8Array() constructor Full support. Chrome7. Toggle history Full support. Edge12...
Constructor without parameters Full support....
Read more >Body Data is unsupported format, expected data to be one of ...
Body Data is unsupported format, expected data to be one of: string | Uint8Array | Buffer | Readable | ReadableStream | Blob #2145....
Read more >Uint8Array Buffer / String conversion in javascript - Support
The keyword here is arbitrary. If the MutableData is expected to hold UTF-8 encoded data, then it's fine of course. I just got...
Read more >ArrayBuffer, binary arrays - The Modern JavaScript Tutorial
ArrayBuffer, binary arrays · Uint8Array – treats each byte in ArrayBuffer as a separate number, with possible values from 0 to 255 (a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
is that a buffer inside of an array?
[ buffer ]
i would definitely take a look at what is being returned before passing to arweave-js. i think maybe Typescript is trying to help you, which is why you had to force it by usingas unknown
.in theory you would just need to change this line here, destructuring to:
const [ file ] = await admin.storage().bucket('my-bucket').file(filePath).download();
Hey @cormacncheese , I haven’t used GCS with Arweave so not sure what is happening here. But, I also think this is related to not sending the right data type.
You can always give a try to submit the tx to mainnet too, to see what happens. Should receive the same error message.