Marius Ailinca
05/25/2022, 11:41 AMfun bytesToFile(byteArray: ByteArray){
val blob = Blob(byteArray.toTypedArray(), BlobPropertyBag("application/vnd.ms-excel"))
val link = document.createElement("a") as HTMLAnchorElement
link.href = URL.Companion.createObjectURL(blob)
link.download = "test.xlsx"
link.click()
//document.removeChild(link)
}
Any idea what it might be wrong?Big Chungus
05/25/2022, 11:58 AMMarius Ailinca
05/25/2022, 1:07 PMreturn base64String.body().decodeBase64Bytes()
. I did a unit test on the Java side with the decode/encode base64 functions and they do work. I am quite new on the web/js world so excuse my ignorance and many thanks!Marius Ailinca
05/25/2022, 2:56 PM8075342008880-61-115-718400
. A normal file, decoded with xxd looks like this: 504b 0304 1400 0808 0800 a789 b954 0000 PK...........T..
They are the same values only integers.Marius Ailinca
05/25/2022, 4:33 PMfun bytesToFile(data: String) {
val link = document.createElement("a") as HTMLAnchorElement
val dataUrl = "data:octet/stream;base64,$data"
fetch(dataUrl).then {
it.blob().then {
val urlBlob = js("URL.createObjectURL(it)")
link.href = urlBlob
link.download = "new_test.xlsx"
link.click()
}
}
}
Maybe not the most elegant way but it works! 🙂