Scala.js – 如何将Array[Byte]转换为Blob?

huangapple go评论78阅读模式
英文:

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))
}

huangapple
  • 本文由 发表于 2023年6月12日 18:33:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76455786.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定