This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Mastering Corda: Blockchain for Java Developers and have Jamiel Sheikh on-line!
See this thread for details.
Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Absolute path to a local file in the user computer

 
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there local file manipulation that's been done with JavaScript that can actually get the absolute path to a file or folder when the user chooses with a directory or file picker?

Specifically, I'd like to read/show the ABSOLUTE PATH from a file and open the file if the user requests it. At this point I'm not worried about gaining permissions and am just assuming I already have full permissions to these files.
 
Marshal
Posts: 67497
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. Security concerns prevent the browser from having such access to the file system.
 
Castiel Snow
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:No. Security concerns prevent the browser from having such access to the file system.



Is there anyway to bypass that?
Extensions?
Java apps?
Anything?
Im using SpringBoot
 
Bear Bibeault
Marshal
Posts: 67497
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It wouldn't be much of a security measure if it could be easily bypassed.

Spring Boot and other Java apps run on the server and have no access to the client machine.

What is it that you are specifically trying to accomplish? You may need to run an agent on the client (which of course requires the permission of, and actions by, the user).
 
Saloon Keeper
Posts: 6798
162
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While the JavaScript File API -which is available in most browsers- lets you access files that the user chooses, it deliberately hides the path information. It does allow you to work with the file contents, though, thus enabling some form of "opening the file" that you mentioned within the web app.

But if you need something like this, you may want to consider if a web app is really the right way to go, or if a desktop app might be better suited.
 
Master Rancher
Posts: 4083
37
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want just anything, here is a technque I have used to call a java program from a browser.  I normally use it through a bookmark on the browers' bookmark bar but it seems to work from an external html file:


<html>
<head>
<script type="text/javascript">
 document.location = 'D:/JavaDevelopment/runtime ExecuteJava.jar"';   //<<<< calls a java program
</script>
</head>
<body>
Will ExecJava work here?    YES it does!!!
</body>
</html>


It requires an entry in the Windows Registry that defines: ExecJava
 
Saloon Keeper
Posts: 23006
156
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Node,js you can use the path resolve() function to get the absolute path to a file on the server. Don't expect that to work on a web page, however. As Bear has said, security (sandbox) constraints forbid a web page from directly accessing the file system. The closest you can get is via file upload/download, where you can pre-populate the file dialog box. But there the browser itself is responsible for reading/writing files and will only do so by explicit permission from the user.

A webapp server cannot actually access client files at all. They don't share the same file system (usually), so you can't just call the "open" function on a file path on a foreign computer. Web-based "files" are copies of data, not the actual data itself and that data is embedded within the request POST stream (for uploads) or response stream (for downloads). The browser is responsible for copying in the data for a POST and saving data for a download, Never client-side user logic.

That, incidentally, was one of the reasons ActiveX failed. Too much scope for mischief. Plus, of course, some of us don't use Windows.

Aside from the lack of direct filesystem access, it would be a Really Bad Idea to allow the server to control the client's computer. A bad-intentioned server could absolutely litter an unsuspecting client with virus files if that were allowed. For a similar reason, web pages cannot automatically print without approval from the user. Not only because of possible exploits via the printing system, but simply because otherwise I could spitefully print out page after page of garbage and waste paper and printer resources.

Incidentally, file uploads from Internet Explorer often contained the full client-side pathname as the "filename" parameter of the POST. That wasn't a good idea, since while the server cannot use the path directly, it does hint at where the user stores things, and the first law of securty is to never volunteer any more information than you have to. Most web clients uploaded only the file name without the path.



 
Castiel Snow
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please don't update an old post like that. Users will not notice the update after they have replied. I have reverted the edit. Please post a new post with the additional information.



Sorry, I thought was best to not pollute it. But I understand. Sorry.
Good thing I had a copy of this. Would be a pain to write all over lol

Im converting a DesktopApp(JavaFx) to a WebApp (Spring Boot).

The DesktopApp has a field called 'hyperlink', which is a String field. The User utilizes the JFileChooser to pick a file or even a folder and save the ABSOLUTE PATH to this file on the field called hyperlink. The user can also manually set the field and for example, set a internet URL (for example, a dropbox link with public access).

This field is then saved in the database.

Other users can then try to access this file. It usually works because users save the absolute path of the local network or even Internet URL's like 'https://redacted.something.com/file.txt.

In this case, a user could open the app, find this 'hyperlink' field and click open --> If its a URL, it will open a browser page. If its a network file, it will open explorer.exe on the absolute path given by the field.

However, this functionality must now exist on the spring boot version.

Problem

Was unknown to me that Browser's security forbid you to access local files. So now, I can neither get the absolute path with the HTML file chooser or access a local file with it.

How should I deal with this?

Someone mentioned me I should think about using either an extension in browser OR a java plugin (ew?).
 
Tim Holloway
Saloon Keeper
Posts: 23006
156
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Best bet is to not catalog files under someone's local file pathname to begin with. "Usually" isn't a word I like to hear next to "works" anyway.

You cannot escape the sandbox using plugins and even if you could, you'd never sell it on the open Internet. Java applets could relax sandbox rules enough to do that, but applets had so many security issues that they should be considered as dead technology.

It sounds like you aren't actually up/downloading files, just their local pathnames. Not really a net-friendly scheme when all's said and done. Probably better done with a standard Java Application (which can access the local filesystem) or just leave it in JavaFX.
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic