ZargorNET
09/30/2018, 6:47 PMval bytes = ByteArrayOutputStream()
val multipart = call.receiveMultipart()
multipart.forEachPart { part ->
if (part is PartData.FileItem) {
val stream = part.streamProvider()
var data = stream.read()
while (data != -1) {
bytes.write(data)
data = stream.read()
}
stream.close()
}
part.dispose()
}
e5l
09/30/2018, 7:25 PMZargorNET
09/30/2018, 7:31 PMpost("/u") {
. In that route I'm asking for an authentication header(just a simple string password) so that just I can upload images: if (call.request.header("Auth") != configObj.uploadPw) {
call.response.status(HttpStatusCode.Unauthorized)
call.respondText("""{"error": "unauthorized"}""", ContentType.Application.Json)
return@post
}
And then I'm trying to get all bytes from the uploading images with the method above.
My request is a POST request with the auth header included. The body is "form-data". And in the body I'm creating a field named "file" with the specific image I want to uploade5l
09/30/2018, 7:33 PMform-data
you mean multipart/form-data
?ZargorNET
09/30/2018, 7:34 PMPOST /u HTTP/1.1
Host: 127.0.0.1:8089
Auth: mypassword
Cache-Control: no-cache
Postman-Token: 9eaafc43-81e9-4620-9136-3dd625a8bfac
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="400px-KeyboardLayout-Danish.png"
Content-Type: image/png
------WebKitFormBoundary7MA4YWxkTrZu0gW--
e5l
10/01/2018, 11:01 AM