Richard Ulysse [3:17 PM] Hello, does anyone know ...
# ktor
r
Richard Ulysse [3:17 PM] Hello, does anyone know upload a file using the fetch API with Kotlin/JS. Currently using Ktor and my code looks like this: _httpClient_.post("$_BackendServerURL_/") { _contentType_(ContentType.MultiPart.Any) setBody(MultiPartFormDataContent( formData*{* // append("uploadDocument", inputAsset.uploadDocument) append( key ="String", value = Json._encodeToString_(String), Headers.build*{* append(HttpHeaders.ContentType,"multipart/form-data") append(HttpHeaders.ContentDisposition,File(Object.uploadDocument).) }) }, )) } I constantly get different errors, but one of the frequent errors I get is:
Copy code
{
  "type": "about:blank",
  "title": "Unsupported Media Type",
  "status": 415,
  "detail": "Content-Type 'application/octet-stream' is not supported.",
  "instance": "/asset-management/"
}
I would love to get help if possible! Thank you
a
You can use a packet analyzer application, e.g. WireShark, to compare requests made with Ktor on Kotlin/JS and another HTTP client like Postman which can satisfy the server's requirements, to find out the issue.
👍 1
p
we have identified this issue we use insomnia to test our API Service and modified our API call in our ReactJS app (using KTOR client API) 1. Issue is insomnia client is streaming our atachement part in chunks 2. We are trying to to the same using in Browser however we are challenged by lack of Compatibility for obvious reasons in the Browser File Object vs Kotlin JVM file object that one can use
InputProvider(file.length()) { file.inputStream().asInput() }
as per post we expect that this will send data in Chunks and not as whole https://stackoverflow.com/questions/69830965/ktor-client-post-multipart-form-data As per post above shows how to do this on JVM
a
Unfortunately, the streaming of request bodies isn't supported by Ktor on the Kotlin/JS targets. You can use the fetch API instead.
p
Ok thank you
Do you have any ETA when this will be supported?