英文:
Scala.js - How to convert Array[Byte] to Blob?
问题
DOM API需要Blob
,但我只有Array[Byte]
。我该如何进行转换?
import org.scalajs.dom.Blob
def toBlob(input: Array[Byte]): Blob = {
// 需要翻译的代码部分
}
英文:
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
得分: 0
这对我来说有效(不确定js.Array
是否适用)。
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))
}
英文:
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))
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论