How to upload file with specific file name?

Hi everybody,
I am using Vaadin 13 with Uploader, but i want to to require the right file name and file type to when on upload,

Ex:
If user use my Uploader and choose the file to upload, they can only choose a file named “text.txt”, other files are not allowed.

I found a stackoverflow post about this idea:
https://stackoverflow.com/questions/37477028/upload-a-file-with-specific-filename
But how can i do this in Vaadin?

Thank you.!

A your linked SO thread explains, it is not possible to restrain files by their name in the front-end, only by their file type. An additional restraint needs to be implemented in the back-end aka after they tried to upload it.

you could for example check the filename of the uploaded file inside the succeededListener of the Upload component

// these two are frontend restrictions - no round trip to the server needed for max files and file type
upload.setMaxFiles(UPLOAD_MAX_FILES);
upload.setAcceptedFileTypes(".txt");

// this is a backend restriction - user can select "invalid" files to upload (as long as all frontend restrictions are valid), and after a server roundtrip we tell the user he cannot do that
upload.setSucceededListener(event -> {
	if(!event.getFileName().equals("text")){
		Notification.show("You can only uplaod files with the name 'text.txt'");
	} else {
		// do stuff with the uploaded file, which is called "text.txt"
	}
}

It is also good practice to let the user know of such a file name restiction beforehand.

Kaspar Scherrer:
A your linked SO thread explains, it is not possible to restrain files by their name in the front-end, only by their file type. An additional restraint needs to be implemented in the back-end aka after they tried to upload it.

you could for example check the filename of the uploaded file inside the succeededListener of the Upload component

// these two are frontend restrictions - no round trip to the server needed for max files and file type
upload.setMaxFiles(UPLOAD_MAX_FILES);
upload.setAcceptedFileTypes(".txt");

// this is a backend restriction - user can select "invalid" files to upload (as long as all frontend restrictions are valid), and after a server roundtrip we tell the user he cannot do that
upload.setSucceededListener(event -> {
	if(!event.getFileName().equals("text")){
		Notification.show("You can only uplaod files with the name 'text.txt'");
	} else {
		// do stuff with the uploaded file, which is called "text.txt"
	}
}

It is also good practice to let the user know of such a file name restiction beforehand.

Thank you for reply, i just re-read my linked thread and… yes, it impossible to do that :stuck_out_tongue:
I am doing the same way as your example. Thank you for help :smiley: