From f348c805301fb7e7ca96259db211125bc33ca3bb Mon Sep 17 00:00:00 2001 From: "pzrr@qq.com" Date: Sun, 21 Jan 2018 08:55:47 +0800 Subject: [PATCH] =?UTF-8?q?####=20Version=201.4.6=20*=20BUG=20Fixed:=20Upl?= =?UTF-8?q?oadFile=E5=BA=9F=E5=BC=83Bytes=E6=8E=A5=E5=8F=A3=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9EReadBytes=E6=8E=A5=E5=8F=A3=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E8=BF=94=E5=9B=9E=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=9C=AC=E8=BA=AB=20*=20=E9=9C=80=E8=A6=81=E7=89=B9=E5=88=AB?= =?UTF-8?q?=E6=B3=A8=E6=84=8F=EF=BC=8C=E7=94=B1=E4=BA=8Eio.read=E5=85=B7?= =?UTF-8?q?=E6=9C=89=E4=B8=80=E6=AC=A1=E6=80=A7=E7=89=B9=E6=80=A7=EF=BC=8C?= =?UTF-8?q?UploadFile.SaveFile=E4=B8=8EUploadFile.ReadBytes=E5=8F=AA?= =?UTF-8?q?=E8=83=BD=E4=BD=BF=E7=94=A8=E5=85=B6=E4=B8=AD=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=EF=BC=8C=E5=8F=A6=E5=A4=96=E4=B8=80=E4=B8=AA=E5=B0=86=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E5=B8=B8=E8=8E=B7=E5=8F=96=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=20*=20=E5=A2=9E=E5=8A=A0dotweb.Version=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E8=BE=93=E5=87=BA=E6=A1=86=E6=9E=B6=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=20*=20Readme=E5=A2=9E=E5=8A=A0=E5=9F=BA=E4=BA=8Edotwe?= =?UTF-8?q?b=E4=B8=8Emapper=E5=AE=9E=E7=8E=B0=E7=9A=84yulibaozi.com?= =?UTF-8?q?=E5=8D=9A=E5=AE=A2=E6=BA=90=E7=A0=81=E9=93=BE=E6=8E=A5=20*=2020?= =?UTF-8?q?18-01-21=2009:00?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++++---- consts.go | 5 +++++ uploadfile.go | 23 ++++++++++------------- version.MD | 6 ++++++ 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3b71354..53fdafb 100644 --- a/README.md +++ b/README.md @@ -272,15 +272,19 @@ type NotFoundHandle func(http.ResponseWriter, *http.Request) websocket - golang.org/x/net/websocket
redis - github.com/garyburd/redigo/redis - +
+yaml - gopkg.in/yaml.v2 ## 相关项目 -#### TokenServer -项目简介:token服务,提供token一致性服务以及相关的全局ID生成服务等 - #### LongWeb 项目简介:http长连接网关服务,提供Websocket及长轮询服务 +#### yulibaozi.com +项目简介:基于dotweb与mapper的一款go的博客程序 + +#### TokenServer +项目简介:token服务,提供token一致性服务以及相关的全局ID生成服务等 + ## 贡献名单 目前已经有几位朋友在为框架一起做努力,我们将在合适的时间向大家展现,谢谢他们的支持! diff --git a/consts.go b/consts.go index a582bc2..90921c3 100644 --- a/consts.go +++ b/consts.go @@ -1,5 +1,10 @@ package dotweb +//dotweb const +const ( + Version = "1.4.5.1" +) + //Log define const ( LogTarget_Default = "dotweb_default" diff --git a/uploadfile.go b/uploadfile.go index 48d9cbb..c18b16a 100644 --- a/uploadfile.go +++ b/uploadfile.go @@ -3,6 +3,7 @@ package dotweb import ( "bytes" "errors" + "io" "mime/multipart" "os" "path/filepath" @@ -14,7 +15,6 @@ type UploadFile struct { fileExt string //file extensions fileName string fileSize int64 - content []byte } func NewUploadFile(file multipart.File, header *multipart.FileHeader) *UploadFile { @@ -23,7 +23,6 @@ func NewUploadFile(file multipart.File, header *multipart.FileHeader) *UploadFil Header: header, fileName: header.Filename, fileExt: filepath.Ext(header.Filename), //update for issue #99 - content: parseFileToBytes(file), } } @@ -47,8 +46,10 @@ func (f *UploadFile) Size() int64 { return f.fileSize } -//save file in server-local with filename -func (f *UploadFile) SaveFile(fileName string) (size int, err error) { +// SaveFile save file in server-local with filename +// special: +// if you SaveFile, it's will cause empty data when use ReadBytes +func (f *UploadFile) SaveFile(fileName string) (size int64, err error) { size = 0 if fileName == "" { return size, errors.New("filename not allow empty") @@ -59,9 +60,7 @@ func (f *UploadFile) SaveFile(fileName string) (size int, err error) { return size, err } defer fileWriter.Close() - f.File.Read(f.content) - //size, err = io.Copy(fileWriter, f.File) - size, err = fileWriter.Write(f.content) + size, err = io.Copy(fileWriter, f.File) return size, err } @@ -71,12 +70,10 @@ func (f *UploadFile) GetFileExt() string { } // Bytes returns a slice of byte hoding the UploadFile.File -func (f *UploadFile) Bytes() []byte { - return f.content -} - -func parseFileToBytes(file multipart.File) []byte { +// special: +// if you read bytes, it's will cause empty data in UploadFile.File, so you use SaveFile will no any data to save +func (f *UploadFile) ReadBytes() []byte { buf := new(bytes.Buffer) - buf.ReadFrom(file) + buf.ReadFrom(f.File) return buf.Bytes() } diff --git a/version.MD b/version.MD index 163290a..5c0477e 100644 --- a/version.MD +++ b/version.MD @@ -1,5 +1,11 @@ ## dotweb版本记录: +#### Version 1.4.6 +* BUG Fixed: UploadFile废弃Bytes接口,新增ReadBytes接口,用于返回上传文件本身 +* 需要特别注意,由于io.read具有一次性特性,UploadFile.SaveFile与UploadFile.ReadBytes只能使用其中一个,另外一个将无法正常获取数据 +* 增加dotweb.Version,用于输出框架版本号 +* 2018-01-21 09:00 + #### Version 1.4.5 * 新增yaml格式配置文件支持,具体参考 example/config/dotweb.yaml * config新增UnmarshalYaml\MarshalYaml\MarshalYamlString,提供针对Yaml的常规处理