Skip to content

Commit f348c80

Browse files
author
pzrr@qq.com
committed
#### Version 1.4.6
* BUG Fixed: UploadFile废弃Bytes接口,新增ReadBytes接口,用于返回上传文件本身 * 需要特别注意,由于io.read具有一次性特性,UploadFile.SaveFile与UploadFile.ReadBytes只能使用其中一个,另外一个将无法正常获取数据 * 增加dotweb.Version,用于输出框架版本号 * Readme增加基于dotweb与mapper实现的yulibaozi.com博客源码链接 * 2018-01-21 09:00
1 parent 8ef9618 commit f348c80

4 files changed

Lines changed: 29 additions & 17 deletions

File tree

‎README.md‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,19 @@ type NotFoundHandle func(http.ResponseWriter, *http.Request)
272272
websocket - golang.org/x/net/websocket
273273
<br>
274274
redis - github.com/garyburd/redigo/redis
275-
275+
<br>
276+
yaml - gopkg.in/yaml.v2
276277

277278
## 相关项目
278-
#### <a href="https://github.com/devfeel/tokenserver" target="_blank">TokenServer</a>
279-
项目简介:token服务,提供token一致性服务以及相关的全局ID生成服务等
280-
281279
#### <a href="https://github.com/devfeel/longweb" target="_blank">LongWeb</a>
282280
项目简介:http长连接网关服务,提供Websocket及长轮询服务
283281

282+
#### <a href="https://github.com/yulibaozi/yulibaozi.com" target="_blank">yulibaozi.com</a>
283+
项目简介:基于dotweb与mapper的一款go的博客程序
284+
285+
#### <a href="https://github.com/devfeel/tokenserver" target="_blank">TokenServer</a>
286+
项目简介:token服务,提供token一致性服务以及相关的全局ID生成服务等
287+
284288
## 贡献名单
285289
目前已经有几位朋友在为框架一起做努力,我们将在合适的时间向大家展现,谢谢他们的支持!
286290

‎consts.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package dotweb
22

3+
//dotweb const
4+
const (
5+
Version = "1.4.5.1"
6+
)
7+
38
//Log define
49
const (
510
LogTarget_Default = "dotweb_default"

‎uploadfile.go‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dotweb
33
import (
44
"bytes"
55
"errors"
6+
"io"
67
"mime/multipart"
78
"os"
89
"path/filepath"
@@ -14,7 +15,6 @@ type UploadFile struct {
1415
fileExt string //file extensions
1516
fileName string
1617
fileSize int64
17-
content []byte
1818
}
1919

2020
func NewUploadFile(file multipart.File, header *multipart.FileHeader) *UploadFile {
@@ -23,7 +23,6 @@ func NewUploadFile(file multipart.File, header *multipart.FileHeader) *UploadFil
2323
Header: header,
2424
fileName: header.Filename,
2525
fileExt: filepath.Ext(header.Filename), //update for issue #99
26-
content: parseFileToBytes(file),
2726
}
2827
}
2928

@@ -47,8 +46,10 @@ func (f *UploadFile) Size() int64 {
4746
return f.fileSize
4847
}
4948

50-
//save file in server-local with filename
51-
func (f *UploadFile) SaveFile(fileName string) (size int, err error) {
49+
// SaveFile save file in server-local with filename
50+
// special:
51+
// if you SaveFile, it's will cause empty data when use ReadBytes
52+
func (f *UploadFile) SaveFile(fileName string) (size int64, err error) {
5253
size = 0
5354
if fileName == "" {
5455
return size, errors.New("filename not allow empty")
@@ -59,9 +60,7 @@ func (f *UploadFile) SaveFile(fileName string) (size int, err error) {
5960
return size, err
6061
}
6162
defer fileWriter.Close()
62-
f.File.Read(f.content)
63-
//size, err = io.Copy(fileWriter, f.File)
64-
size, err = fileWriter.Write(f.content)
63+
size, err = io.Copy(fileWriter, f.File)
6564
return size, err
6665
}
6766

@@ -71,12 +70,10 @@ func (f *UploadFile) GetFileExt() string {
7170
}
7271

7372
// Bytes returns a slice of byte hoding the UploadFile.File
74-
func (f *UploadFile) Bytes() []byte {
75-
return f.content
76-
}
77-
78-
func parseFileToBytes(file multipart.File) []byte {
73+
// special:
74+
// if you read bytes, it's will cause empty data in UploadFile.File, so you use SaveFile will no any data to save
75+
func (f *UploadFile) ReadBytes() []byte {
7976
buf := new(bytes.Buffer)
80-
buf.ReadFrom(file)
77+
buf.ReadFrom(f.File)
8178
return buf.Bytes()
8279
}

‎version.MD‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## dotweb版本记录:
22

3+
#### Version 1.4.6
4+
* BUG Fixed: UploadFile废弃Bytes接口,新增ReadBytes接口,用于返回上传文件本身
5+
* 需要特别注意,由于io.read具有一次性特性,UploadFile.SaveFile与UploadFile.ReadBytes只能使用其中一个,另外一个将无法正常获取数据
6+
* 增加dotweb.Version,用于输出框架版本号
7+
* 2018-01-21 09:00
8+
39
#### Version 1.4.5
410
* 新增yaml格式配置文件支持,具体参考 example/config/dotweb.yaml
511
* config新增UnmarshalYaml\MarshalYaml\MarshalYamlString,提供针对Yaml的常规处理

0 commit comments

Comments
 (0)