I am working on uploading via Ktor MutliPartFormDa...
# ktor
t
I am working on uploading via Ktor MutliPartFormDataContent an image from MP module (File on Java and NSData on iOS). I see an Input/AbstractInput interface that appears needed to wrap the native types so Ktor can pull in the requisite data. I don’t suppose anybody has an example of implementing AbstractInput? I am trying, but it does not seem to advance past the first block. Thank you!
e
Hi @tylerwilson, the recommended way to do it is to use
ByteReadPacket
. You can create it with
buildPacket { }
.
c
@e5l do you have any example about buildPacket? I can't get it working. Or maybe you @tylerwilson? I need to do exactly what you requested (upload file from android + ios)
t
I had to put that on the back burner, so i went back to my vanilla Retrofit/Alamofire implementation. I hope to get back to it next week, since this is tha last API I have not moved to Ktor.
c
I finally got it working after 3 days straight on this issue. Actually the problem was partially caused by the server. Anyway my 2 cents, maybe this can help you too. I have file.outputStream() on android and nsData.toByteArray() on iOS, where toByteArray is just a function for converting NSData to KotlinByteArray (just search "nsdata bytearray" on slack, it's full of these impl). And remember to set the size of the file to the InputProvider, especially if your backend is laravel like the one I'm dealing with :P
InputProvider(avatar.size.toLong()) { buildPacket { writeFully(avatar) } }
Good luck @tylerwilson!
t
Thank you so much for the follow-up. I will definitely refer back to this when I get back to it. And I will then post an update too. We are using mostly AWS API Gateway, but there some older Apache/Oracle servers we are dealing with too methinks. Thank you!