[Web/HTML]input tag in form must have **name** attribute

Android

Howdy!

I'm developing new application which can transfer and upload files between smarthphone and any devices which can show browser.

I was struggling such posted title stuff and tell you guys why I couldn't do that.

Problem

I wanted to send any kinds of files by using form of HTML and I developed it by ktor.

I tried to upload file by POST method in form tag but nothing came in server.

form(
    method = FormMethod.post,
    encType = FormEncType.multipartFormData,
    action = "http://${connectiveManagerWrapper.getIPAddress()}:8080/${
        getRelativePath(
            absPath = absPath
        )
    }/upload",
) {
    input(type = InputType.file, classes = "clear-decoration") {}
    input(type = InputType.submit, classes = "clear-decoration") {
        value = "Upload"
    }
}

Solution

I needed to add name attribute in input which has file type like below.

    input(type = InputType.file, classes = "clear-decoration", name = "file") {}

After that I could get file data by form.

Hope you find the solution through this article.

コメント

タイトルとURLをコピーしました