https://kotlinlang.org logo
#ktor
Title
# ktor
c

CLOVIS

06/12/2020, 12:59 PM
Hi, I found how to use `FileReader`etc to upload an image with multipart requests, but I don't understand how I can unit test it. I'm searching for a way to get access to a JS
File
or
Blob
from a URL (it's a PNG image). I found the example that shows how to do this with Kotlin/JVM, but nothing for Kotlin/JS at the moment. Is it possible?
s

spand

06/12/2020, 1:41 PM
File and Blob are local files, not something that resides on the network so I am not sure what you mean.
In my own test I use this to stub a File:
Copy code
private fun StubFile(filename: String) = File(arrayOf(), filename)
Obviously you can put whatever content you want in the bytearray yourself
c

CLOVIS

06/12/2020, 2:41 PM
I see. I have written the code to read the contents of a file and send them via the network (the project requires that the client can upload files in multiplatform), and from Java I can just read a local file, but from JS I don't see how to unit test that. So far the only examples I've seen are to get an
<input type="file">
but I obviously can't use that for automated tests...
So I'm searching for a way to get a dummy File (which may represent any image as long as it's a valid one), and I thought I'd be able to download an image from an URL or something like this, but guess not.
8 Views