Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
zhima1234 committed Jun 25, 2017
1 parent 7f9c694 commit 7f241ee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/http/controller/image.go
Expand Up @@ -9,6 +9,7 @@ package controller
import (
"encoding/json"
"global"
"io"
"io/ioutil"
"logic"
"net/http"
Expand Down Expand Up @@ -59,6 +60,7 @@ func (self ImageController) QuickUpload(ctx echo.Context) error {

fileName := goutils.Md5Buf(buf) + filepath.Ext(fileHeader.Filename)
imgDir := times.Format("ymd")
file.Seek(0, io.SeekStart)
path, err := logic.DefaultUploader.UploadImage(ctx, file, imgDir, buf, filepath.Ext(fileHeader.Filename))
if err != nil {
return self.quickUploadFail(ctx, "文件上传失败!")
Expand Down Expand Up @@ -133,6 +135,7 @@ func (ImageController) Upload(ctx echo.Context) error {
cdnDomain += "/"
}

file.Seek(0, io.SeekStart)
path, err := logic.DefaultUploader.UploadImage(ctx, file, imgDir, buf, filepath.Ext(fileHeader.Filename))
if err != nil {
return fail(ctx, 5, "文件上传失败!")
Expand Down
8 changes: 4 additions & 4 deletions src/logic/uploader.go
Expand Up @@ -114,7 +114,7 @@ func (this *UploaderLogic) uploadLocalFile(localFile, key string) (err error) {
return
}

func (this *UploaderLogic) uploadMemoryFile(r gio.Reader, key string) (err error) {
func (this *UploaderLogic) uploadMemoryFile(r gio.Reader, key string, size int) (err error) {
this.genUpToken()

var ret io.PutRet
Expand All @@ -130,7 +130,7 @@ func (this *UploaderLogic) uploadMemoryFile(r gio.Reader, key string) (err error
// key 为文件存储的标识
// r 为io.Reader类型,用于从其读取数据
// extra 为上传文件的额外信息,可为空, 详情见 io.PutExtra, 可选
err = io.Put(nil, &ret, this.uptoken, key, r, extra)
err = io.Put2(nil, &ret, this.uptoken, key, r, int64(size), extra)

// 上传产生错误
if err != nil {
Expand Down Expand Up @@ -172,7 +172,7 @@ func (this *UploaderLogic) UploadImage(ctx context.Context, reader gio.Reader, i
}

path := imgDir + "/" + md5 + ext
if err = this.uploadMemoryFile(reader, path); err != nil {
if err = this.uploadMemoryFile(reader, path, len(buf)); err != nil {
return "", err
}

Expand Down Expand Up @@ -226,7 +226,7 @@ func (this *UploaderLogic) TransferUrl(ctx context.Context, origUrl string, pref
return origUrl, errors.New("文件太大")
}

err = this.uploadMemoryFile(reader, path)
err = this.uploadMemoryFile(reader, path, len(buf))
if err != nil {
return origUrl, err
}
Expand Down
1 change: 1 addition & 0 deletions static/js/admin/forms.js
Expand Up @@ -104,6 +104,7 @@ jQuery(document).ready(function($){
jAlert("操作成功", "信息");
} else {
jAlert(data.error, "出错");
return;
}
// $('#tooltip').text("操作成功!");
if (typeof formSuccCallback !== "undefined") {
Expand Down

0 comments on commit 7f241ee

Please sign in to comment.