# How to obtain full file path without using FileUpload in zk

1 1

How do we get the full file path, without using FileUpload event? I searched the forums and it seems that the only way highlighted, is to first upload the media, then use media.getName(), and finally the getAbsolutePath() method. But, if I just want to have the file path rather than upload a 50 MB file to do just that, this obviously adds a lot of overhead. How do I get the path without uploading the corresponding file? My current code is given below :-

<button hflex="1" upload="true, maxsize=-1, native" label = "..."


public void onFileUpload(
@ContextParam(ContextType.BIND_CONTEXT)
BindContext ctx) {

Media media = upEvent.getMedia();

File myFile = new File(media.getName());
setPackageSource(myFile.getAbsolutePath().toString());
updateModelUi();
}
}


Thanks in advance to any kind soul, who answers my query. Regards and have a nice day!

delete retag edit

@cor3000 Thanks for the reply. To clarify: This is part of a SQL Server Agent Job manager software running on a local machine, that needs a file's path in order to access it and use it in processing. While creation, when the user browses a file, I need the selected file's path without uploading it.

( 2021-03-18 01:50:54 +0800 )edit

For simplicity, all I need is the full file path of a selected file (while the user browses and selects one), to be obtained on the Client side, so that it can be passed on as a string for further processing. In doing this, it appears I am unable to get the path in the composer, without uploading.

( 2021-03-18 01:59:52 +0800 )edit

Sort by » oldest newest most voted

cor3000
5868 2 7

That's quite an unusual question. I think I don't fully understand your scenario to give any hints. As of now what you ask for seems impossible.

Without uploading there won't be a file existing at the server so you won't get a path for it. If you wanted to display the path on the client system then you're also out of options since you don't have access the client side file system from the server.

So the question is, what do you really need? Fileupload doesn't seem like the right tool, obviously it's meant for uploading files.

UPDATE 2021-03-18

to my current knowledge there is no way to obtain the path to a local file from within a browsers. Accessing information about he file system is deliberately prevented for security reasons (that includes absolut paths) ... even the file system api is only operating on a virtualised file system (https://developer.mozilla.org/en-US/docs/Web/API/FileandDirectoryEntriesAPI/Introduction#virtual).

If the browser has no access to it, then you can't send this information to the server.

The workaround you found via file upload will actually duplicate the file after uploading inside a temp folder inside the application server. Then this absolute path to the temp folder is used, not the original location.

If you find something giving you direct file system information from inside the browser you should file a bug the the browser vendor to get this fixed.

The only way I see is to ask the user to copy paste the absolute path directly into a textbox and then use this string at server side.

[hide preview]