golang 上传文件(Web版)

时间:2024-10-11 07:03:26

   实现一个简单的页面上传文件功能。

/**
* MyFileUpload01
* @Author:  Jian Junbo
* @Email:   junbojian@
* @Create:  2017/9/17 15:14
* Copyright (c) 2017 Jian Junbo All rights reserved.
*
* Description:  简单的上传文件
*/
package main

import (
    "net/http"
    "fmt"
    "os"
    "io"
    "time"
    "path"
    "strconv"
)

func main() {
    ("/", index)
    ("/upload2", upload)
    err := (":7373", nil)
    if err != nil{
        ("服务器启动失败",())
        return
    }

}
func upload(writer , request *) {
    (32<<20)
    //接收客户端传来的文件 uploadfile 与客户端保持一致
    file, handler, err := ("uploadfile")
    if err != nil{
        (err)
        return
    }
    defer ()