JuliaPluto/PlutoUI.jl

Return absolute path in FilePicker

juliohm opened this issue · 8 comments

The FilePicker returns a dictionary with the name key holding the basename of the selected file. With only the basename it is impossible to recover the full path of the file for further processing with IO packages.

Can this name key hold the absolute path instead?

fonsp commented

Hey! This is not possible because of browser security: https://developer.mozilla.org/en-US/docs/Web/API/File/name

That is interesting. How do people usually load the data from other directories in notebooks then?

I am particularly interested in loading XLSX files with XLSX.readxlsx("/path/to/file.xlsx").

You can do that without the file picker; if you can make sure that the file exists you can use an absolute path; if not, upload the file somewhere and download it in a cell (Downloads.download returns a path you can open)

Not sure I follow @pankgeorg. The file can live anywhere on the user disk. He/she will select the file, you mean I should dump the data key of the FilePicker to a new file in a specific place and then use that absolute path instead?

No - if the file is user defined you can read from the IO object in the file picker Dict: it will be a UInt8 under "data" (file_data["data"]). Does this not work for you?

if you need to, you can write the UInt8 array to a (temp) file and pass that to XLSX.

I can read the data but XLSX.jl expects a filename in XLSX.readxlsx()

@juliohm in actuality you can do the following,

@bind myxlsxfile FilePicker()

and then

workbook = XLSX.readxlsx(myxlsxfile["data"] |> IOBuffer)

That is, readxlsx now supports both reading from a filename or from IO.