rest - Golang services response file -
how can return file service more efficiently in go? example, receive file this
here example use receive file service:
func (b *benefitlisthandler) uploadappend(w http.responsewriter, r *http.request) { r.parsemultipartform(32 << 20) file, handler, err := r.formfile("benefitlistuploadfile") if err != nil { libhttp.encodeerrorresponse(w, err, http.statusinternalservererror) return } defer file.close() f, err := os.openfile("./"+handler.filename, os.o_wronly|os.o_create, 0666) if err != nil { libhttp.encodeerrorresponse(w, err, http.statusinternalservererror) return } defer f.close() io.copy(f, file) go b.readfileappend("./" + handler.filename) libhttp.encodeokresponse(w, true)}
after that, confused how can send file request binary, improve time , consumption.
after information question solution
to specify browser file put header response:
w.header().set("content-disposition", "attachment; filename=nameoffile")
after read file ioutil:
files, err := ioutil.readfile(result)
and @ end use http.responsewriter write []byte of file response
w.write(files)
Comments
Post a Comment