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

[Question] How manage multiple upload file in forms? #1770

Open
badstorm opened this issue Aug 20, 2019 · 0 comments

Comments

@badstorm
Copy link

commented Aug 20, 2019

Description

Is there any way to manage multiple upload file in a form?

Steps to Reproduce the Problem

I try this way:

  1. Crate a new model and add this two fields:
Images      slices.String `json:"images" db:"images"`
ImagesForm  []binding.File  `json:"-" db:"-" form:"imageFiles"`
  1. In the Create method of the model I add:
func (r Resource) Create(c buffalo.Context) error {
    ... 

	var images []string
	for _, img := range myModel.ImagesForm {
		dir := filepath.Join(".", "uploads")
		images = append(images, filepath.Join(dir, img.Filename))
	}
	myModel.Images = images

    ...
}
  1. In the HTML form i add:
    <%= f.FileTag("ImagesForm", {multiple:"multiple"}) %>

Expected Behavior

I need that the slice with images paths must be saved in the Images field of the model.

Actual Behavior

The images var is always null.

Info

-> Go: Checking installation
✓ The `go` executable was found on your system at: /usr/local/go/bin/go

-> Go: Checking minimum version requirements
✓ Your version of Go, 1.12.7, meets the minimum requirements.

-> Go: Checking GOPATH
✓ You appear to be operating inside of your GOPATH.

-> Go: Checking Package Management
⚠ You do not appear to be using a package management system.

It is strongly suggested that you use one of the following package management systems:

* Go Modules (Recommended) - https://gobuffalo.io/en/docs/gomods
* Dep - https://github.com/golang/dep

For help setting up your Go environment please follow the instructions for you platform at:

https://www.gopherguides.com/courses/preparing-your-environment-for-go-development

-> Go: Checking PATH
✓ Your PATH contains /Users/marco.olimpi/Source/GO/bin.

-> Node: Checking installation
✓ The `node` executable was found on your system at: /usr/local/bin/node

-> Node: Checking minimum version requirements
✓ Your version of Node, v10.15.3, meets the minimum requirements.

-> NPM: Checking installation
✓ The `npm` executable was found on your system at: /usr/local/bin/npm

-> NPM: Checking minimum version requirements
✓ Your version of NPM, 6.4.1, meets the minimum requirements.

-> Yarn: Checking installation
✓ The `yarnpkg` executable was found on your system at: /usr/local/bin/yarnpkg

-> Yarn: Checking minimum version requirements
✓ Your version of Yarn, 1.17.3, meets the minimum requirements.

-> PostgreSQL: Checking installation
✘ The `postgres` executable could not be found on your system.
For help setting up your Postgres environment please follow the instructions for you platform at:

https://www.postgresql.org/download/

-> MySQL: Checking installation
✘ The `mysql` executable could not be found on your system.
For help setting up your MySQL environment please follow the instructions for you platform at:

https://www.mysql.com/downloads/

-> SQLite3: Checking installation
✓ The `sqlite3` executable was found on your system at: /usr/bin/sqlite3

-> SQLite3: Checking minimum version requirements
✓ Your version of SQLite3, 3.24.0, meets the minimum requirements.

-> Cockroach: Checking installation
✘ The `cockroach` executable could not be found on your system.
For help setting up your Cockroach environment please follow the instructions for you platform at:

https://www.cockroachlabs.com/docs/stable/

-> Buffalo: Checking installation
✓ The `buffalo` executable was found on your system at: /usr/local/bin/buffalo

-> Buffalo: Checking minimum version requirements
✓ Your version of Buffalo, v0.14.9, meets the minimum requirements.

-> Buffalo: Application Details
Pwd         /Users/marco.olimpi/Source/GO/src/duckpage.com/ido02
Root        /Users/marco.olimpi/Source/GO/src/duckpage.com/ido02
GoPath      /Users/marco.olimpi/Source/GO
PackagePkg  duckpage.com/ido02
ActionsPkg  duckpage.com/ido02/actions
ModelsPkg   duckpage.com/ido02/models
GriftsPkg   duckpage.com/ido02/grifts
WithModules false
Name        ido02
Bin         bin/ido02
VCS         git
WithPop     true
WithSQLite  false
WithDep     false
WithWebpack true
WithNodeJs  true
WithYarn    true
WithDocker  true
WithGrifts  true
AsWeb       true
AsAPI       false
InApp       true
PackageJSON {map[]}

-> Buffalo: config/buffalo-app.toml
name = "ido02"
bin = "bin/ido02"
vcs = "git"
with_pop = true
with_sqlite = false
with_dep = false
with_webpack = true
with_nodejs = true
with_yarn = true
with_docker = true
with_grifts = true
as_web = true
as_api = false

-> Buffalo: config/buffalo-plugins.toml
[[plugin]]
  binary = "buffalo-auth"
  go_get = "github.com/gobuffalo/buffalo-auth"

[[plugin]]
  binary = "buffalo-pop"
  go_get = "github.com/gobuffalo/buffalo-pop"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.