0

DOM API requires Blob but all I have is Array[Byte]. How can I do the conversion?

import org.scalajs.dom.Blob

def toBlob(input: Array[Byte]): Blob = {
  // code in question
}

1 Answer 1

0

This worked for me (not sure about js.Array though).

import org.scalajs.dom.Blob
import scala.scalajs.js
import scalajs.js.typedarray.AB2TA

def toBlob(input: Array[Byte]): Blob = {
  new Blob(js.Array(input.toTypedArray))
}
Sign up to request clarification or add additional context in comments.

4 Comments

The js.Array wrapper should not be required. new Blob(input.toTypedArray) should work as well.
@sjrd Found: scala.scalajs.js.typedarray.Int8Array Required: scala.scalajs.js.Iterable[org.scalajs².dom.BlobPart]
Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?
Added some more info

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.