question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expected data to be a string, Uint8Array or ArrayBuffer

See original GitHub issue

When 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:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rosmcmahoncommented, Jul 20, 2022

looks like an array buffer

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 using as 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();

1reaction
cedrikingcommented, Jul 20, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found