0
DART + golang을 사용하여 서버에 작은 오디오 파일을 업로드하고 있습니다. POST가 끝날 때까지 아무 것도 잘 돌아 가지 않고 아무것도 반환하지 않습니다. 입력 파일의 레이블 텍스트를 변경할 수 있도록 파일 이름을 반환하고 싶습니다.golang 서버 업로드 파일 응답 net :: ERR_EMPTY_RESPONSE
1) GOLANG :
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"time"
"fmt"
"os"
"io"
)
http.HandleFunc("/upload", webUploadHandler)
[...]
func webUploadHandler(w http.ResponseWriter, r *http.Request) {
file, header, err := r.FormFile("file") // the FormFile function takes in the POST input id file
defer file.Close()
if err != nil {
fmt.Fprintln(w, err)
return
}
out, err := os.Create("/tmp/uploadedfile")
if err != nil {
fmt.Fprintf(w, "Unable to create the file for writing. Check your write access privilege")
return
}
defer out.Close()
// write the content from POST to the file
_, err = io.Copy(out, file)
if err != nil {
fmt.Fprintln(w, err)
}
fmt.Fprintf(w,"File uploaded successfully : ")
fmt.Fprintf(w, header.Filename)
}
2) DART 응답, 경고
window.alert("upload complete");
가 크롬 콘솔에서
3) 오류를 작동합니다
POST http://localhost:9999/upload net::ERR_EMPTY_RESPONSE
난 아주 그래서 새로운 도움을 주시면 감사하겠습니다.
는 위의 코드에서
I 코드에서 버그가 아니라 Chro의 버그 일 가능성이 높습니다. mium, 다른 브라우저에서 일어나는가 /'''curl'''을 시도 할 때? Chrome에서 –
과 동일합니다. FF로 얻을 수 있습니다 : 요청 URL : \t http : // localhost : 9999/업로드 요청 방법 : \t POST 상태 코드 : – bboy
어떻게 응답 할 수 있습니까? 마지막 2 줄인'Fprintf'의 목적은 무엇입니까? – bboy