JuliaPluto / PlutoUI.jl

https://featured.plutojl.org/basic/plutoui.jl
The Unlicense
299 stars 54 forks source link

Return absolute path in FilePicker #246

Closed juliohm closed 1 year ago

juliohm commented 1 year ago

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 1 year ago

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

juliohm commented 1 year ago

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").

pankgeorg commented 1 year ago

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)

juliohm commented 1 year ago

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?

pankgeorg commented 1 year ago

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?

juliohm commented 1 year ago

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

Em ter., 7 de mar. de 2023 18:20, Παναγιώτης Γεωργακόπουλος < @.***> escreveu:

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?

— Reply to this email directly, view it on GitHub https://github.com/JuliaPluto/PlutoUI.jl/issues/246#issuecomment-1458890557, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZQW3NAPC7N2ULE5X464VDW26RCZANCNFSM6AAAAAAVSQ2KTA . You are receiving this because you authored the thread.Message ID: @.***>

pankgeorg commented 1 year ago

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

grahamgill commented 1 year ago

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.