gowut
gowut copied to clipboard
Issue#9
Since file input mechanism is requested by many (issues#9), I made it.
Now you can add an input box that accepts file path in the following manner.
win := gwu.NewWindow("main", "test")
tb := gwu.NewFileInputBox("file input box")
win.Add(tb)
Your proposed solution just provides a textfield component with type=file. This is not what is requested in issue #9.
The need is for a component which can upload files without leaving the page, in the background. An HTML <input type=file> tag has no real value without the uploading mechanism (upload in background and server side to receive / handle the file).
The need is for a component which can upload files without leaving the page, in the background. An HTML
<input type=file>tag has no real value without the uploading mechanism (upload in background and server side to receive / handle the file).
Yes, as @icza indicates, the upload needs to happen like all other components, in an SPA fashion. So more needs to be in place for this to meet the use case.
Here is my guess as to what is needed:
- Add new
EventType:ETypeFileUpload - Add new method to
gwu.Event:
type Event interface {
...
//Either just expose an http.Request.Body:
Body() io.ReadCloser
// Or, expose the whole http.Request as other info in the Request may be of interest, like Request.Context(), Request.WithContext(), Request.ContentLength, Request.MultipartForm, etc?
Request() *http.Request
...
}
- Usage something like:
win := gwu.NewWindow("main", "test") tb := gwu.NewFileInputBox("file") win.Add(tb) tb.AddEHandlerFunc(func(e gwu.Event) { // get the reader via the above Event.Body() or the Event.Request.Body() reader := e.Request().Body() // read from reader and write somewhere or process directly ... err := reader.Close() if err != nil{ //handle error } }, gwu.ETypeFileUpload)