gowut icon indicating copy to clipboard operation
gowut copied to clipboard

Issue#9

Open KMimura opened this issue 6 years ago • 2 comments
trafficstars

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)

KMimura avatar Feb 25 '19 04:02 KMimura

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

icza avatar Feb 25 '19 09:02 icza

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:

  1. Add new EventType: ETypeFileUpload
  2. 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
 	...
}
  1. 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)
    

 

gnewton avatar Feb 25 '19 21:02 gnewton