0

How to obtain full file path without using FileUpload in zk

asked 2021-03-15 16:59:00 +0800

Swarnaditya gravatar image Swarnaditya
1 1

updated 2021-03-18 01:46:26 +0800

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 = "..."
        onUpload="@command('onFileUpload')"
        disabled="@load(stepGeneralVM.isServerEntered)"/>

public void onFileUpload(
        @ContextParam(ContextType.BIND_CONTEXT)
        BindContext ctx) {
    UploadEvent upEvent = null;
    Object objUploadEvent = ctx.getTriggerEvent();

    if (objUploadEvent != null && (objUploadEvent instanceof UploadEvent)) {
        upEvent = (UploadEvent) objUploadEvent;

        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 flag offensive retag edit

Comments

@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.

Swarnaditya ( 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.

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

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-03-17 10:22:19 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2021-03-18 16:26:33 +0800

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.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2021-03-15 16:59:00 +0800

Seen: 14 times

Last updated: Mar 18 '21

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More