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?

Daniel
  • 49
  • 1
  • 1
  • 4

2 Answers2

2

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

vbuzze
  • 930
  • 1
  • 11
  • 25
2
    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)">
Luis Luis Maia Maia
  • 681
  • 1
  • 10
  • 30