|
|
|
@ -28,6 +28,41 @@ type Args struct { |
|
|
|
Zpfile, Fname string |
|
|
|
} |
|
|
|
|
|
|
|
// 获取文件大小的接口
|
|
|
|
type Size interface { |
|
|
|
Size() int64 |
|
|
|
} |
|
|
|
|
|
|
|
// 获取文件信息的接口
|
|
|
|
type Stat interface { |
|
|
|
Stat() (os.FileInfo, error) |
|
|
|
} |
|
|
|
|
|
|
|
// 显示状态
|
|
|
|
func ReceiveStatus(w http.ResponseWriter, r *http.Request) { |
|
|
|
switch r.Method { |
|
|
|
// 显示当前传送文件的大小
|
|
|
|
case http.MethodPost: |
|
|
|
file, _, err := r.FormFile("file") |
|
|
|
if err != nil { |
|
|
|
http.Error(w, err.Error(), 500) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if statInterface, ok := file.(Stat); ok { |
|
|
|
fileInfo, _ := statInterface.Stat() |
|
|
|
fmt.Fprintf(w, "上传文件的大小为: %d", fileInfo.Size()) |
|
|
|
} |
|
|
|
|
|
|
|
if sizeInterface, ok := file.(Size); ok { |
|
|
|
fmt.Fprintf(w, "上传文件的大小为: %d", sizeInterface.Size()) |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// fmt.Fprintf(w, r.Method)
|
|
|
|
} |
|
|
|
|
|
|
|
// 接收 上传
|
|
|
|
func ReceiveHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
switch r.Method { |
|
|
|
|