CLOVIS
11/11/2020, 11:37 AMorg.w3c.files.File
as argument, but I don't know how to build one from JS (on JVM I could just new java.io.File("path")
but I've heard that's not possible on JS?)Nicholas Bilyk
11/11/2020, 1:47 PMCLOVIS
11/11/2020, 3:52 PMNicholas Bilyk
11/11/2020, 3:59 PMCLOVIS
11/11/2020, 6:35 PMval promise = fetch("some PNG I found").await()
val blob = promise.asDynamic().blob() as Promise<Blob>
val data = blob.await()
js("new File([data], \"filename.png\", {type: \"image/png\"})")
But that fails with
ReferenceError: File is not defined
CLOVIS
11/11/2020, 6:41 PMNicholas Bilyk
11/11/2020, 6:42 PMNicholas Bilyk
11/11/2020, 6:47 PMCLOVIS
11/11/2020, 6:53 PMFileReader.readAsArrayBuffer(Blob)
, so I guess that's an option, yesCLOVIS
11/11/2020, 6:54 PMNicholas Bilyk
11/11/2020, 6:54 PMCLOVIS
11/11/2020, 6:55 PMjsBrowserTest
, so I think that's what I'm doing already? xDCLOVIS
11/11/2020, 6:55 PMNicholas Bilyk
11/11/2020, 6:58 PM@Test
fun testFile() {
val f = File(arrayOf(Blob(arrayOf(1, 2, 3))), "Test")
println(f)
}
this works when I run browserTestCLOVIS
11/11/2020, 7:04 PMNicholas Bilyk
11/11/2020, 7:04 PMNicholas Bilyk
11/11/2020, 7:05 PMkotlin {
js {
browser {
testTask {
useKarma {
useChromeHeadless()
}
}
}
Nicholas Bilyk
11/11/2020, 7:05 PMCLOVIS
11/11/2020, 7:06 PMNicholas Bilyk
11/11/2020, 7:08 PMuseKarma {
useChromeHeadless()
}
Nicholas Bilyk
11/11/2020, 7:10 PMCLOVIS
11/11/2020, 7:13 PMCLOVIS
11/11/2020, 7:15 PMuseKarma
? The IDE doesn't want to autocomplete my gradle setup right now 😕Nicholas Bilyk
11/11/2020, 7:16 PMCLOVIS
11/11/2020, 7:17 PMtimeout.set(Duration?)
but I have no idea how to provide a Duration
, and it won't import java.time.Duration
xDNicholas Bilyk
11/11/2020, 7:18 PMNicholas Bilyk
11/11/2020, 7:19 PMNicholas Bilyk
11/11/2020, 7:20 PMCLOVIS
11/11/2020, 7:21 PMCLOVIS
11/11/2020, 7:23 PMCLOVIS
11/11/2020, 7:26 PMFile
constructor works, but the fetch
now fails.
I'm not convinced yet that adding Kotlin to JS solves its issues... Well, I'll keep searching, thanks a lot for the help ^^Nicholas Bilyk
11/11/2020, 7:26 PMNicholas Bilyk
11/11/2020, 7:27 PMCLOVIS
11/11/2020, 7:28 PMCLOVIS
11/11/2020, 7:29 PMNicholas Bilyk
11/11/2020, 7:29 PMNicholas Bilyk
11/11/2020, 7:29 PMNicholas Bilyk
11/11/2020, 7:29 PMCLOVIS
11/11/2020, 7:30 PMcommon
anyway, so it shouldn't take too much workNicholas Bilyk
11/11/2020, 7:31 PMNicholas Bilyk
11/11/2020, 7:32 PMNicholas Bilyk
11/11/2020, 7:33 PMNicholas Bilyk
11/11/2020, 7:33 PM