N
N
Nikolino2019-03-15 20:17:53
go
Nikolino, 2019-03-15 20:17:53

How to check if input file is empty?

simple form

<form action="/upload" method="POST" enctype="multipart/form-data">
            <input type="file" name="file">
            <input type="submit" value="Submit">
</form>

How to check if the submitted form is empty? Or that specifically input name="file" is not set when submitting the form?
fmt.Println(r.PostFormValue("file")) produces an empty string even if I submit a file.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2019-03-15
@ghostiam

try
in ok it will be true if the field was sent when sending and false if the field was not in the request,
just don't forget to parse the request body with

const maxMemory = 32 << 20 // 32 MB
r.ParseMultipartForm(maxMemory)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question