校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > golang簡單獲取上傳文件大小的實(shí)現(xiàn)代碼

golang簡單獲取上傳文件大小的實(shí)現(xiàn)代碼

熱門標(biāo)簽:電梯外呼訪客系統(tǒng) 電銷機(jī)器人可以補(bǔ)救房產(chǎn)中介嗎 谷歌便利店地圖標(biāo)注 成都呼叫中心外呼系統(tǒng)平臺 騰訊外呼系統(tǒng)價(jià)格 百度地圖標(biāo)注搜索關(guān)鍵詞 ?兓? 最短的地圖標(biāo)注 浙江人工智能外呼管理系統(tǒng)

本文實(shí)例講述了golang簡單獲取上傳文件大小的方法。分享給大家供大家參考,具體如下:

復(fù)制代碼 代碼如下:
package main
import (
    "fmt"
    "io"
    "net/http"
    "log"
    "os"
)
// 獲取文件大小的接口
type Size interface {
    Size() int64
}
// 獲取文件信息的接口
type Stat interface {
    Stat() (os.FileInfo, error)
}
// hello world, the web server
func HelloServer(w http.ResponseWriter, r *http.Request) {
    if "POST" == r.Method {
        file, _, err := r.FormFile("userfile")
        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
    }
    // 上傳頁面
    w.Header().Add("Content-Type", "text/html")
    w.WriteHeader(200)
    html := `
form enctype="multipart/form-data" action="/hello" method="POST">
    Send this file: input name="userfile" type="file" />
    input type="submit" value="Send File" />
/form>
`
    io.WriteString(w, html)
}
func main() {
    http.HandleFunc("/hello", HelloServer)
    err := http.ListenAndServe(":12345", nil)
    if err != nil {
        log.Fatal("ListenAndServe: ", err)
    }
}

希望本文所述對大家Go語言程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:
  • golang實(shí)現(xiàn)的文件上傳下載小工具
  • golang語言實(shí)現(xiàn)的文件上傳與文件下載功能示例
  • Golang實(shí)現(xiàn)異步上傳文件支持進(jìn)度條查詢的方法
  • Golang+Android基于HttpURLConnection實(shí)現(xiàn)的文件上傳功能示例
  • Golang實(shí)現(xiàn)http文件上傳小功能的案例

標(biāo)簽:眉山 宜昌 雅安 紹興 邢臺 七臺河 上海 盤錦

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《golang簡單獲取上傳文件大小的實(shí)現(xiàn)代碼》,本文關(guān)鍵詞  golang,簡單,獲取,上傳,文件,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《golang簡單獲取上傳文件大小的實(shí)現(xiàn)代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于golang簡單獲取上傳文件大小的實(shí)現(xiàn)代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 门源| 那曲县| 巨野县| 龙川县| 阳山县| 本溪市| 岢岚县| 松潘县| 张家口市| 闵行区| 怀化市| 泽普县| 什邡市| 永州市| 达尔| 武平县| 永寿县| 英山县| 桐柏县| 大埔区| 磐石市| 吉木乃县| 雷州市| 海安县| 眉山市| 弥渡县| 小金县| 上高县| 聊城市| 涞源县| 平顶山市| 浑源县| 曲阜市| 中阳县| 拜泉县| 万安县| 罗定市| 高台县| 闸北区| 宜黄县| 英山县|