T
T
tr1ck12020-07-10 11:40:57
Java
tr1ck1, 2020-07-10 11:40:57

How to make a mask for an uploaded file in java?

Hi all.
How can I make a mask for an uploaded file so that when a user selects a file on the disk, only those files that match the specified mask are shown?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Roo, 2020-07-10
@xez

Java has nothing to do with it. It all happens on the client side, in the browser.
Here is all the information: https://developer.mozilla.org/ru/docs/Web/HTML/Ele...

O
Orkhan, 2020-07-10
Hasanly @azerphoenix

Hello!
If the code should work in the browser, then you need to validate using html or js. If you
need validation using html, then there is an accept attribute for the
input htmlbook.ru/html/input/accept
accept only images: <input type="file" name="img" accept="image/*">
But if you need server-side validation, then that's different...
You can connect Apache Common Utils
https://commons.apache.org/proper/commons-io/
And then check the MIME type of the file and if it doesn't match the desired type, then return some message to the client that the file type is incorrect

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question