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

[BUG]a big file upload will respond an error #129

Closed
godcong opened this issue Dec 31, 2019 · 3 comments
Closed

[BUG]a big file upload will respond an error #129

godcong opened this issue Dec 31, 2019 · 3 comments
Assignees
Labels
🐛bug Something isn't working

Comments

@godcong
Copy link

godcong commented Dec 31, 2019

bug 描述 [详细地描述 bug,让大家都能理解]

	formList := fTable.GetForm()
	formList.AddField("Address", "address", db.Varchar, form.File)
	formList.AddField("Name", "name", db.Varchar, form.Text)
	formList.SetTable("files").SetTitle("Files").SetDescription("Files")

i used form.File to upload a File.
when the file is very big, this will reponse an error

期望结果 [描述你原本期望看到的结果]

success to upload

复现代码 [提供可复现的代码,仓库,或线上示例]

image

版本信息:

  • GoAdmin 版本: [e.g. 1.0.0]
  • golang 版本
  • 浏览器环境
  • 开发环境 [e.g. mac OS]

其他信息 [如截图等其他信息可以贴在这里]

@godcong godcong added the 🐛bug Something isn't working label Dec 31, 2019
@chenhg5 chenhg5 self-assigned this Dec 31, 2019
@godcong
Copy link
Author

godcong commented Dec 31, 2019

// SaveMultipartFile used in a local Uploader which help to save file in the local path.
func SaveMultipartFile(fh *multipart.FileHeader, path string) (err error) {
	var f multipart.File
	f, err = fh.Open()
	closed := false
	if err != nil {
		return err
	}
	defer func() {
		if !closed {
			if err2 := f.Close(); err2 != nil {
				err = err2
			}
		}
	}()

	if ff, ok := f.(*os.File); ok {
		err = f.Close()
		closed = true
		dir, name := filepath.Split(path)
		return moveFile(ff.Name(), dir, name, true)
	}

	ff, err := os.Create(path)
	if err != nil {
		return err
	}
	defer func() {
		if err2 := ff.Close(); err2 != nil {
			err = err2
		}
	}()
	_, err = copyZeroAlloc(ff, f)
	return err
}

i changed the SaveMultipartFile functions
it has two problems.

  1. os.Rename can't used when 'f' was opened
  2. os.Rename can only used on same disk. if between two harddisk copy, you need used other functions...

otherwise, i want get the filename and filesize when upload a file.
can you add some function to get these two arguments?
i was added these on my local source.

func Upload(c UploadFun, form *multipart.Form) error {
...
		form.Value["_filename_"+k] = []string{fileObj.Filename}
		form.Value["_filesize_"+k] = []string{humanize.Bytes(uint64(fileObj.Size))}
		form.Value[k] = []string{pathStr}
...

@chenhg5
Copy link
Collaborator

chenhg5 commented Dec 31, 2019

Fixed. #9ac6a

@godcong
Copy link
Author

godcong commented Jan 1, 2020

fixed runs ok

@godcong godcong closed this as completed Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants