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);
}
Hoppeduppeanut
  • 1,109
  • 6
  • 20
  • 29
MathanKumar
  • 102
  • 1
  • 1
  • 11
  • You have "FileType" twice. I think the full path is not available for security reasons. – PepitoSh Jun 08 '18 at 05:09
  • What do you mean by the `FilePath`? You mean the path on the local PC? If so, **why** do you want that? – mjwills Jun 08 '18 at 05:10
  • I am selecting file from my local drive so i want selected file path – MathanKumar Jun 08 '18 at 05:14
  • Possible duplicate of [ for IE gives full path, need file name only](https://stackoverflow.com/questions/2200100/input-type-file-for-ie-gives-full-path-need-file-name-only) – mjwills Jun 08 '18 at 05:15

2 Answers2

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?

Hoppeduppeanut
  • 1,109
  • 6
  • 20
  • 29
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.

Ipse
  • 186
  • 1
  • 3