add example for custom uploading file name for ghttp.Server
@@ -10,10 +10,11 @@ import (
"fmt"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
+ "github.com/gogf/gf/os/gfile"
"time"
)
-func ExampleGetServer() {
+func ExampleHelloWorld() {
s := g.Server()
s.BindHandler("/", func(r *ghttp.Request) {
r.Response.Write("hello world")
@@ -22,6 +23,27 @@ func ExampleGetServer() {
s.Run()
}
+// Custom saving file name.
+func ExampleUploadFile_Save() {
+ s := g.Server()
+ s.BindHandler("/upload", func(r *ghttp.Request) {
+ file := r.GetUploadFile("TestFile")
+ if file == nil {
+ r.Response.Write("empty file")
+ return
+ }
+ file.Filename = "MyCustomFileName.txt"
+ fileName, err := file.Save(gfile.TempDir())
+ if err != nil {
+ r.Response.Write(err)
+ return
+ }
+ r.Response.Write(fileName)
+ })
+ s.SetPort(8999)
+ s.Run()
+}
+
func ExampleClientResponse_RawDump() {
response, err := g.Client().Get("https://goframe.org")
if err != nil {
