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

调整FormFile和FormType的优先级 #248

Closed
guonaihong opened this issue Jul 22, 2020 · 0 comments
Closed

调整FormFile和FormType的优先级 #248

guonaihong opened this issue Jul 22, 2020 · 0 comments

Comments

@guonaihong
Copy link
Owner

如果File不为空,且FormFile包裹的是一个正确的文件名,File的名字就是multipart/form-data filename里面的名字。
代码举例

package main

import (
	"fmt"

	"github.com/guonaihong/gout"
)

func main() {
	err := gout.POST(":1234").Debug(true).SetForm(gout.H{"voice": gout.FormType{FileName: "new-file-name", File: gout.FormFile("./voice.pcm")}}).Do()
	fmt.Printf("err:%s\n", err)
}
  • 现在的http 抓包
> POST / HTTP/1.1
> Content-Type: multipart/form-data; boundary=c13f1e919fc51a4110b8d387faccb9da8828ed72dcd6f939ed9893b1cf44
>

--c13f1e919fc51a4110b8d387faccb9da8828ed72dcd6f939ed9893b1cf44
Content-Disposition: form-data; name="voice"; filename="./voice.pcm"
Content-Type: application/octet-stream

wowowowow
wowowowow
wowowowow

--c13f1e919fc51a4110b8d387faccb9da8828ed72dcd6f939ed9893b1cf44--


< HTTP/1.1 200 OK
< Server: gurl-server
< Date: Wed, 22 Jul 2020 10:46:42 GMT
< Content-Length: 0
  • 修改后的接口
> POST / HTTP/1.1
> Content-Type: multipart/form-data; boundary=c13f1e919fc51a4110b8d387faccb9da8828ed72dcd6f939ed9893b1cf44
>

--c13f1e919fc51a4110b8d387faccb9da8828ed72dcd6f939ed9893b1cf44
Content-Disposition: form-data; name="voice"; filename="new-file-name"
Content-Type: application/octet-stream

wowowowow
wowowowow
wowowowow
wowowowow
wowowowow
wowowowow

--c13f1e919fc51a4110b8d387faccb9da8828ed72dcd6f939ed9893b1cf44--


< HTTP/1.1 200 OK
< Server: gurl-server
< Date: Wed, 22 Jul 2020 10:46:42 GMT
< Content-Length: 0

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

No branches or pull requests

1 participant