Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#9 #46

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open

Issue#9 #46

wants to merge 6 commits into from

Conversation

KMimura
Copy link

@KMimura KMimura commented Feb 25, 2019

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)

@icza
Copy link
Owner

icza commented Feb 25, 2019

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

@gnewton
Copy link

gnewton commented Feb 25, 2019

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)
    

 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants