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

Add convenient method to save uploaded multi-part file #82

Closed
jeevatkm opened this issue Jul 23, 2017 · 7 comments
Closed

Add convenient method to save uploaded multi-part file #82

jeevatkm opened this issue Jul 23, 2017 · 7 comments
Assignees
Labels
feature lib-ahttp HTTP - extension to standard one
Projects

Comments

@jeevatkm
Copy link
Member

jeevatkm commented Jul 23, 2017

Add convenient method to save uploaded multi-part file from the request. Currently aah user can has easily access uploaded file via Req.FormFile(key). However it would be good to have following methods on Request struct:

SaveFile(key, dstFile string) error
// e.g.: SaveFiles("avatar_pic", "/mnt/uploads/avatars/username.png")

SaveFiles(key, dstPath string) []error // uses the request filename
// e.g.: SaveFiles("files", "/mnt/uploads")

So that aah user simply call. Example of SaveFile method as follows:

func (u *UploadController) Upload() {
	// Create destination filepath based on your logic
	destFile := "/mnt/uploads/avatars/username.png"

	if err := u.Req.SaveFile("avatar_pic", destFile); err {
		log.Error(err)
		u.Reply().BadRequest().Text("Upload file error: %s", err.Error())
		return
	}

	u.Reply().Ok().Text("Avatar picture uploaded successfully.")
}
@jeevatkm jeevatkm added feature lib-ahttp HTTP - extension to standard one labels Jul 23, 2017
@jeevatkm jeevatkm added this to the v0.8 Milestone milestone Jul 23, 2017
@jeevatkm jeevatkm self-assigned this Jul 23, 2017
@adelowo
Copy link
Contributor

adelowo commented Jul 23, 2017

I can work on this but should SaveFile() really be on the Request struct ?

@jeevatkm
Copy link
Member Author

Where do you feel is appropriate to put it? Please let me know your thoughts.

@go-aah go-aah deleted a comment from adelowo Jul 23, 2017
@adelowo
Copy link
Contributor

adelowo commented Jul 23, 2017

Not too sure but may be something like this could work ?

//Bad naming
type FileUpload struct {}

func (f *FileUpload) Upload (r *http.Request, key, destFile string) error {
}

The main reason for this is to reduce the size of Req.. I feel there is too much stuff on that struct

@jeevatkm
Copy link
Member Author

Aim is to provide easy use and less memory allocation. If we create struct and provide implementation passing req instance then is it utility method.

I see one more spot other then Request is Context struct.

u.SaveFile("avatar_pic", destFile)

We can go with Context struct. I will update the design description.

@jeevatkm jeevatkm added aah Framework scope and removed lib-ahttp HTTP - extension to standard one labels Jul 23, 2017
@adelowo
Copy link
Contributor

adelowo commented Jul 24, 2017

Not to troll but it seems better placed on the Request than Context 😄 ... It is all up to you though..

Context or Request ? I should still be able work on the implementation

@jeevatkm
Copy link
Member Author

Okay 😄 let's go with Request then. That's what I thought of better place.

I will update the design. Also please let me know if you have time after this implementation.

@jeevatkm jeevatkm added lib-ahttp HTTP - extension to standard one and removed aah Framework scope labels Jul 24, 2017
@jeevatkm jeevatkm added this to v0.8 Iteration (Not started) in aah Roadmap Jul 29, 2017
@jeevatkm jeevatkm moved this from v0.8 Iteration to v0.8 - In Progress in aah Roadmap Aug 4, 2017
@jeevatkm
Copy link
Member Author

jeevatkm commented Aug 4, 2017

It's done.

@jeevatkm jeevatkm closed this as completed Aug 4, 2017
@jeevatkm jeevatkm moved this from v0.8 - In Progress to Done in aah Roadmap Aug 4, 2017
@jeevatkm jeevatkm moved this from Released to Audience to v0.8 - Completed in aah Roadmap Aug 10, 2017
jeevatkm added a commit to go-aah/docs that referenced this issue Aug 13, 2017
@jeevatkm jeevatkm moved this from v0.8 - Completed to Released to Audience in aah Roadmap Sep 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature lib-ahttp HTTP - extension to standard one
Projects
aah Roadmap
  
Released to Audience
Development

No branches or pull requests

2 participants