-
|
Using html tag for UI, when user selects a file or folder, how to make the go code get the full path of the selected file, in order to read from it? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
|
By your own method, you would need to create a binding in the backend using the path as a string parameter and then use Personally, I would recommend creating a binding in the backend and then use the OpenDirectoryDialog instead giving the user their native file picker. If you do choose this route, here is an example implementation This does mean that if the user cancels the operation you will be returned "" so, need to consider that in your frontend code however |
Beta Was this translation helpful? Give feedback.
-
Thank you. |
Beta Was this translation helpful? Give feedback.
-
|
tried on wails v2, got exception. func (a *App) GetFolder(name string) string {
fmt.Println(" --------- got name from frontend: ", name)
path, err := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{})
if err != nil {
fmt.Printf("GetFolder error: %v\n", err)
return fmt.Sprintf("error: %v", err)
}
return path
}running wails dev on windows 11 AMD64, the line fmt.Println(" --------- got name from frontend: ", name) is printed out correctly, then followed by quite a lot lines of error messages, part of them are: goroutine 58 gp=0xc00006bdc0 m=nil [semacquire]:
runtime.gopark(0xada740, 0xf192a0, 0x12, 0x5, 0x4)
C:/Apps/Go/src/runtime/proc.go:424 +0xfc fp=0xc000176550 sp=0xc000176520 pc=0x1f6b1c
runtime.goparkunlock(0xf192a0?, 0x1?, 0x0?, 0xc0004080c0?)
C:/Apps/Go/src/runtime/proc.go:430 +0x25 fp=0xc000176580 sp=0xc000176550 pc=0x1c4125
runtime.semacquire1(0xc000120808, 0x0, 0x1, 0x0, 0x12)
C:/Apps/Go/src/runtime/sema.go:178 +0x197 fp=0xc0001765d0 sp=0xc000176580 pc=0x1d57f7
sync.runtime_Semacquire(0xc000120800?)
C:/Apps/Go/src/runtime/sema.go:71 +0x25 fp=0xc000176608 sp=0xc0001765d0 pc=0x1f7ec5
sync.(*WaitGroup).Wait(0xc000120800)
C:/Apps/Go/src/sync/waitgroup.go:118 +0x8b fp=0xc000176670 sp=0xc000176608 pc=0x2161ab
github.com/wailsapp/wails/v2/internal/frontend/desktop/windows.invokeSync[...](0xc0002068c0, 0xc0002242e0)
C:/Users/development/go/pkg/mod/github.com/wailsapp/wails/[email protected]/internal/frontend/desktop/windows/window.go:334 +0x19c fp=0xc0001766b8 sp=0xc000176670 pc=0x8a1a9c
github.com/wailsapp/wails/v2/internal/frontend/desktop/windows.(*Frontend).showCfdDialog(0xc00021c080, 0xc000033c20, 0x0)
C:/Users/development/go/pkg/mod/github.com/wailsapp/wails/[email protected]/internal/frontend/desktop/windows/dialog.go:140 +0x105 fp=0xc000176750 sp=0xc0001766b8 pc=0x892c65
github.com/wailsapp/wails/v2/internal/frontend/desktop/windows.(*Frontend).OpenDirectoryDialog(0xc00021c080, {{0xb17200, 0x1}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0, 0x0}, ...})
C:/Users/development/go/pkg/mod/github.com/wailsapp/wails/[email protected]/internal/frontend/desktop/windows/dialog.go:45 +0x291 fp=0xc0001768e0 sp=0xc000176750 pc=0x8913b1
github.com/wailsapp/wails/v2/internal/frontend/devserver.(*DevWebServer).OpenDirectoryDialog(0xc00024a2d0, {{0xb17200, 0x1}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0, 0x0}, ...})
<autogenerated>:1 +0x95 fp=0xc0001769a8 sp=0xc0001768e0 pc=0x969c55
github.com/wailsapp/wails/v2/pkg/runtime.OpenDirectoryDialog({0xb21bb8, 0xc000210ae0}, {{0xb17200, 0x1}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0, ...}, ...})
C:/Users/development/go/pkg/mod/github.com/wailsapp/wails/[email protected]/pkg/runtime/dialog.go:40 +0x1d8 fp=0xc000176ac0 sp=0xc0001769a8 pc=0x701e78
main.(*App).GetFolder(0xc000033bf0, {0xc0001207d8, 0x6})
C:/Users/development/wails/wcreatorv2/app.go:33 +0x178 fp=0xc000176c78 sp=0xc000176ac0 pc=0x97a798
runtime.call32(0xc0001c48a0, 0xc000216270, 0x0, 0x0, 0x0, 0x18, 0xc000177070)
C:/Apps/Go/src/runtime/asm_amd64.s:776 +0x48 fp=0xc000176ca8 sp=0xc000176c78 pc=0x1fcfe8
runtime.reflectcall(0x0?, 0x8?, 0x8?, 0x33508?, 0xc0?, 0x12?, 0x9bc9a0?)
<autogenerated>:1 +0x36 fp=0xc000176ce8 sp=0xc000176ca8 pc=0x204c56
reflect.Value.call({0xa00ca0, 0xc000033bf0, 0x213}, {0xa8a608, 0x4}, {0xc000116150, 0x1, 0x1})
C:/Apps/Go/src/reflect/value.go:581 +0xea5 fp=0xc0001776d8 sp=0xc000176ce8 pc=0x299705
reflect.Value.Call({0xa00ca0, 0xc000033bf0, 0x213}, {0xc000116150, 0x1, 0x1})
C:/Apps/Go/src/reflect/value.go:365 +0xb3 fp=0xc000177758 sp=0xc0001776d8 pc=0x2986d3
github.com/wailsapp/wails/v2/internal/binding.(*BoundMethod).Call(0xc000218230, {0xc000032d90, 0x1, 0x1})
C:/Users/development/go/pkg/mod/github.com/wailsapp/wails/[email protected]/internal/binding/boundMethod.go:72 +0x3ff fp=0xc000177a20 sp=0xc000177758 pc=0x850e7f
github.com/wailsapp/wails/v2/internal/frontend/dispatcher.(*Dispatcher).processCallMessage(0xc00022e280, {0xc0001f0000, 0x5d}, {0xb267e0, 0xc00021c080})
C:/Users/development/go/pkg/mod/github.com/wailsapp/wails/[email protected]/internal/frontend/dispatcher/calls.go:45 +0x630 fp=0xc000177d40 sp=0xc000177a20 pc=0x96d0f0
github.com/wailsapp/wails/v2/internal/frontend/dispatcher.(*Dispatcher).ProcessMessage(0xc00022e280, {0xc0001f0000, 0x5d}, {0xb267e0, 0xc00021c080})
C:/Users/development/go/pkg/mod/github.com/wailsapp/wails/[email protected]/internal/frontend/dispatcher/dispatcher.go:42 +0x22b fp=0xc000177eb0 sp=0xc000177d40 pc=0x96df4b
github.com/wailsapp/wails/v2/internal/frontend/desktop/windows.(*Frontend).dispatchMessage(0xc00021c080, {0xc0001f0000, 0x5d})
C:/Users/development/go/pkg/mod/github.com/wailsapp/wails/[email protected]/internal/frontend/desktop/windows/frontend.go:771 +0x7b fp=0xc000177fa0 sp=0xc000177eb0 pc=0x89b03b
github.com/wailsapp/wails/v2/internal/frontend/desktop/windows.(*Frontend).processMessage.gowrap1()
C:/Users/development/go/pkg/mod/github.com/wailsapp/wails/[email protected]/internal/frontend/desktop/windows/frontend.go:713 +0x3c fp=0xc000177fe0 sp=0xc000177fa0 pc=0x89a1bc
runtime.goexit({})
C:/Apps/Go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000177fe8 sp=0xc000177fe0 pc=0x1fea41
created by github.com/wailsapp/wails/v2/internal/frontend/desktop/windows.(*Frontend).processMessage in goroutine 1
C:/Users/development/go/pkg/mod/github.com/wailsapp/wails/[email protected]/internal/frontend/desktop/windows/frontend.go:713 +0x82anot sure what is exactly the cause. maybe cgo related? |
Beta Was this translation helpful? Give feedback.
I use and test both Linux and MacOS which are working but, not Windows so cannot reproduce your issue or help on this one, sorry.
As a preliminary measure, please can I suggest updating your version of Wails and check if the issue still persists. I see you are using version 2.9.1 which was released back in June last year. Running either of the following will get you on the latest stable version.