Chrome文件浏览器-访问完整路径

I understand that due to security reasons a browser doesn't allow me to access the full path of a file when selected via FileBrowser in a file input field.

Still, I am facing a problem where this feature is needed. Maybe someone can provide an alternative solution where I don't have to reinvent any wheels.

The situation is as follows.

  • The backend and the operating user have both access to the same filesystem.
  • The user has to pick one or multiple file location/s and inform the backend.
  • The backend will then schedule a task.
  • Meanwhile the file contents may be altered by the user but the location will remain the same.
  • The users browser is under our control. So we could use extensions if needed.

Questions

  • Is there any Chrome option that would circumvent the security barrier and allow me to access the full path?
  • Is there any helpful Chrome extension out there?
  • Is there any known alternative solution or "best practice" advise to this problem?

I don't understand why you'd want to be reusing either <input type="file"> or how you'd use the system filebrowser to be able to do this.

Your problem statement would be much easier to solve if you simply listed the files available in a directory, and then performed an action based on that information.

package main

import (
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
    "net/url"
)

func main() {
    r := http.NewServeMux()

    r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        files, err := ioutil.ReadDir(".")
        if err != nil {
            log.Fatal(err)
        }

        out := "<ul>"
        for _, f := range files {
            v := url.Values{}
            v.Add("file", f.Name())
            out += fmt.Sprintf(`<li><a href="/do?%s">%s</a></li>`, v.Encode(), f.Name())
        }
        out += "</ul>"

        w.Header().Set("Content-Type", "text/html")
        fmt.Fprintf(w, out)
    })

    r.HandleFunc("/do", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, r.URL.Query().Get("file"))
    })

    server := &http.Server{
        Addr:    ":8080",
        Handler: r,
    }

    if err := server.ListenAndServe(); err != nil {
        log.Fatal(err)
    }
}

https://play.golang.org/p/bSgm4nAUUYg

Note: This code is not production safe. You have to worry about people potentially accessing directories above where you are .., and all sorts of fun stuff that comes with sharing server information. But, it's just intended to help you get started.

Then, you don't have to worry about what the browser is passing to you, you're completely in control.