2

I have used this code for getting File object of a input file (I have tested it by console.log and it is correct).

var file = event.target.files[0];

The object code that I obtain it's like:

File
 lastModified: 1526981976000
​ lastModifiedDate: Date 2018-05-22T09:39:36.000Z
 Name:"path.png"
 size: 19776
 type: "image/png"
 webkitRelativePath: ""...

However, now I want to get that kind of File object, but through a image path saved into my file system. Is it possible?

3
  • 3
    Possible duplicate of Local file access with javascript Commented May 22, 2018 at 13:47
  • 2
    Not possible in-browser; the browser has no access to the file system. Commented May 22, 2018 at 13:47
  • Check File Object in Javascript Commented May 22, 2018 at 13:50

2 Answers 2

3
    function handleFiles() {
    "use strict";
    var inputElement = document.getElementById("input");
    var fileList = inputElement.files; /* now you can work with the file list */
    var file = {type:"", name:"", size:""};

    for(var k = 0; k < fileList.length; k++){   
    file.name.push(fileList[k].name);
    file.type.push(fileList[k].type);
    file.size.push(fileList[k].size);
    //and others
    }

This works for multiple images files try it

    <h2>Upload images ...</h2>
    <input type="file" id="input" multiple onchange="handleFiles(this.files)">
Sign up to request clarification or add additional context in comments.

2 Comments

Yes I know, but now that image is saved in my file system and I want to get it from Javascript into File object
Im sry but i believe that cant be done, the browser cant access the client file system, that would be a huge red flag
2

The browser can't access the file system of the client, you need to upload the image first

1 Comment

how dangerous would that be

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.