第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

將圖像從 html 表單傳遞給 Go

將圖像從 html 表單傳遞給 Go

Go
BIG陽 2021-08-10 10:40:52
我有一個(gè)包含以下代碼的 html 頁面。<form action="/image" method="post"enctype="multipart/form-data"><label for="file">Filename:</label><input type="file" name="file" id="file"><br><input type="submit" name="submit" value="Submit"></form>然后我有一些 Go 代碼來獲取后端的文件。func uploaderHandler(w http.ResponseWriter, r *http.Request) {   userInput := r.FormValue("file")但是每當(dāng)我嘗試使用 go 腳本中的 userInput 時(shí),它都不返回任何內(nèi)容。我傳遞的變量錯(cuò)了嗎?編輯:我知道如何將文本/密碼的內(nèi)容上傳到 golang。我無法使用代碼將圖像上傳到 Go。編輯 2:閱讀 Go 指南并找到解決方案。見下文。
查看完整描述

1 回答

?
翻閱古今

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超5個(gè)贊

首先您需要使用req.FormFilenot FormValue,然后您必須手動(dòng)將圖像保存到文件中。


像這樣的東西:


func HandleUpload(w http.ResponseWriter, req *http.Request) {

    in, header, err := req.FormFile("file")

    if err != nil {

        //handle error

    }

    defer in.Close()

    //you probably want to make sure header.Filename is unique and 

    // use filepath.Join to put it somewhere else.

    out, err := os.OpenFile(header.Filename, os.O_WRONLY, 0644)

    if err != nil {

        //handle error

    }

    defer out.Close()

    io.Copy(out, in)

    //do other stuff

}


查看完整回答
反對(duì) 回復(fù) 2021-08-10
  • 1 回答
  • 0 關(guān)注
  • 210 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)