0

get selected file path from JavaScript. Hi! I want to get selected file path from JavaScript

<input type="file" class="input-file" id="inputfile" onchange="ReadFile()">

here I want to assign file path to model.

function GetFileProerties() {
    var fileproperties = {
        "FileName": upload.files[0].name,
        "FilePath": ** here i want to assign selected file path ** ,
        "FileType": upload.files[0].name.substr((upload.files[0].name.lastIndexOf('.') + 1)),
        "FileSize": upload.files[0].size,
        "Modified Date": upload.files[0].lastModifiedDate
    }
    return JSON.stringify(fileproperties);
}
4
  • You have "FileType" twice. I think the full path is not available for security reasons. Commented Jun 8, 2018 at 5:09
  • What do you mean by the FilePath? You mean the path on the local PC? If so, why do you want that? Commented Jun 8, 2018 at 5:10
  • I am selecting file from my local drive so i want selected file path Commented Jun 8, 2018 at 5:14
  • Possible duplicate of <input type=‘file’> for IE gives full path, need file name only Commented Jun 8, 2018 at 5:15

2 Answers 2

3

This is not possible in JavaScript due to browser security considerations.

See also: How to get full path of selected file on change of <input type=‘file’> using javascript, jquery-ajax?

Sign up to request clarification or add additional context in comments.

1 Comment

I suspected so.
0

Like you, I used <input type="file"...> to allow user to select file they want me to pull data from, and now need to connect with that file to pull the data. My next attempt is combining event listener and loop to grab the file, path after it is selected.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.