1

Possible Duplicate:
How to get the file path from HTML input form in Firefox 3

Is there any way I can get the complete path of the file from the input file tag without using the 3rd party API ?

<form method="post" action="SendTheFileName">
                <div id="Files_to_be_shared"> 
                      <input type="file" id="File" name="FileTag" />
                      <input type="submit" value="Share" /> 
               </div>
 </form>

Snippet from the servlet :

String fileName = request.getParameter("FileTag");

What I get now from the above java code is just the name of the file selected. How do I get the complete path of the file ?

Community
  • 1
  • 1
saplingPro
  • 20,769
  • 53
  • 137
  • 195
  • 4
    *"How do I get the complete path of the file ?"* The full path is none of your web-apps. business, is the general view. – Andrew Thompson Jan 15 '13 at 13:37
  • @AndrewThompson None of my web-apps business ? ! I need it. – saplingPro Jan 15 '13 at 13:41
  • 3
    No, you actually need the file contents. See also the duplicate link. – BalusC Jan 15 '13 at 13:43
  • @BalusC No. I only need to know the file name and its path. I do not need the contents. I am not asking how to upload a file – saplingPro Jan 15 '13 at 13:44
  • Well, then a web application is the wrong tool for the job. Perhaps you need an applet or flash application. It all depends on the concrete functional requirements which still sounds very strange. – BalusC Jan 15 '13 at 13:45
  • @BalusC why do you say a wrong tool ? I think I can easily get the complete path using apache commons lib using the web app. I wanted to know if it can be done without it..I mean the JDK – saplingPro Jan 15 '13 at 13:47
  • 1
    Oh, you've thus not read the duplicate link. Well, then it ends here. – BalusC Jan 15 '13 at 13:48
  • @BalusC I read the answers. Thank you for the link. Let me describe my situation:A client shares a file. That file name is then sent to the server database.All other clients can see the file names, that a particular client has shared. To get that file,other client connects to that client. Client also acts as a server at the same time and other clients are able to connect to that client that might have an address like :`xxx.xxx.xxx.xxx/app/list`. If i know the full file path, the other user will be able to download the file. – saplingPro Jan 15 '13 at 14:30
  • 1
    For that P2P/Torrent protocols are invented and proven to be much more efficient. HTTP/HTML doesn't support this. If you've really a hard head in; in web development terms, you're better off with embedding a client application (Applet, Silverlight, etc) in a web page. If Applet (Swing), you can get full path with `JFileChooser`. In the end, a desktop applicaiton like as whatever BitTorrent/uTorrent/Emule are doing is much more elegant. – BalusC Jan 15 '13 at 14:32
  • @BalusC _"HTTP protocol doesn't support this"_ I won't be able to make a connection to a node that has its server running ? If I make a connection I won't be able to download the file ? – saplingPro Jan 15 '13 at 14:34
  • 1
    Let's say, it's the wrong tool for the job. – BalusC Jan 15 '13 at 14:34
  • By the way, if your users are still browsing with IE (not sure about the last versions), then you'll get the full path of their uploaded files from a simple call to `request.getParameter("FileTag")`. Because that's what IE sends, instead of the single filename... – Med Jan 15 '13 at 16:48

1 Answers1

0

This question was already answered in other threads, I think that any of this 2 can help you:

How to get full path using <input id="file" name="file" type="file" size="60" > in jsp

How to get full path of file using input type file in javascript?

Just to complete my answer a bit more and since you added the java tag to it, here I will include you a little snippet of code that shows some of the most common information you can get out of a file, but from the java perspective:

package test;

import java.io.File;
import java.io.IOException;

public class FilePaths {

    public static void main(String[] args) throws IOException {

        String[] fileArray = { 
                "C:\\projects\\workspace\\testing\\f1\\f2\\f3\\file5.txt", 
                "folder/file3.txt",
                "../testing/file1.txt", 
                "../testing", 
                "f1/f2"
        };

        for (String f : fileArray) {
            displayInfo(f);
        }

    }

    public static void displayInfo(String f) throws IOException {
        File file = new File(f);
        System.out.println("========================================");
        System.out.println("          name:" + file.getName());
        System.out.println("  is directory:" + file.isDirectory());
        System.out.println("        exists:" + file.exists());
        System.out.println("          path:" + file.getPath());
        System.out.println(" absolute file:" + file.getAbsoluteFile());
        System.out.println(" absolute path:" + file.getAbsolutePath());
        System.out.println("canonical file:" + file.getCanonicalFile());
        System.out.println("canonical path:" + file.getCanonicalPath());
    }

}
Community
  • 1
  • 1
javing
  • 12,307
  • 35
  • 138
  • 211