How to resolve the C:\fakepath?

后端 未结 13 1704
梦如初夏
梦如初夏 2020-11-21 13:34

This is my upload button.



        
13条回答
  •  情歌与酒
    2020-11-21 13:47

    Why don't you just use the target.files?

    (I'm using React JS on this example)

    const onChange = (event) => {
      const value = event.target.value;
    
      // this will return C:\fakepath\somefile.ext
      console.log(value);
    
      const files = event.target.files;
    
      //this will return an ARRAY of File object
      console.log(files);
    }
    
    return (
     
    )
    

    The File object I'm talking above looks like this:

    {
      fullName: "C:\Users\myname\Downloads\somefile.ext"
      lastModified: 1593086858659
      lastModifiedDate: (the date)
      name: "somefile.ext"
      size: 10235546
      type: ""
      webkitRelativePath: ""
    }
    

    So then you can just get the fullName if you wanna get the path.

提交回复
热议问题