Compatible with revel 0.18

This commit is contained in:
lealife
2017-11-30 18:10:59 +08:00
parent 430744a324
commit c6937fd184
11 changed files with 152 additions and 74 deletions

View File

@ -53,16 +53,23 @@ func (c ApiBaseContrller) uploadAttach(name string, noteId string) (ok bool, msg
}
*/
file, handel, err := c.Request.FormFile(name)
if err != nil {
var data []byte
c.Params.Bind(&data, name)
handel := c.Params.Files[name][0]
if data == nil || len(data) == 0 {
return
}
defer file.Close()
data, err := ioutil.ReadAll(file)
if err != nil {
return
}
// file, handel, err := c.Request.FormFile(name)
// if err != nil {
// return
// }
// defer file.Close()
// data, err := ioutil.ReadAll(file)
// if err != nil {
// return
// }
// > 5M?
maxFileSize := configService.GetUploadSize("uploadAttachSize")
if maxFileSize <= 0 {
@ -79,7 +86,7 @@ func (c ApiBaseContrller) uploadAttach(name string, noteId string) (ok bool, msg
filePath := "files/" + GetRandomFilePath(userId, newGuid) + "/attachs"
dir := revel.BasePath + "/" + filePath
err = os.MkdirAll(dir, 0755)
err := os.MkdirAll(dir, 0755)
if err != nil {
return
}
@ -122,11 +129,18 @@ func (c ApiBaseContrller) upload(name string, noteId string, isAttach bool) (ok
if isAttach {
return c.uploadAttach(name, noteId)
}
file, handel, err := c.Request.FormFile(name)
if err != nil {
// file, handel, err := c.Request.FormFile(name)
// if err != nil {
// return
// }
// defer file.Close()
var data []byte
c.Params.Bind(&data, name)
handel := c.Params.Files[name][0]
if data == nil || len(data) == 0 {
return
}
defer file.Close()
newGuid := NewGuid()
// 生成上传路径
@ -135,7 +149,7 @@ func (c ApiBaseContrller) upload(name string, noteId string, isAttach bool) (ok
fileUrlPath := "files/" + GetRandomFilePath(userId, newGuid) + "/images"
dir := revel.BasePath + "/" + fileUrlPath
err = os.MkdirAll(dir, 0755)
err := os.MkdirAll(dir, 0755)
if err != nil {
return
}
@ -148,10 +162,10 @@ func (c ApiBaseContrller) upload(name string, noteId string, isAttach bool) (ok
// }
filename = newGuid + ext
data, err := ioutil.ReadAll(file)
if err != nil {
return
}
// data, err := ioutil.ReadAll(file)
// if err != nil {
// return
// }
maxFileSize := configService.GetUploadSize("uploadImageSize")
if maxFileSize <= 0 {

View File

@ -104,16 +104,23 @@ func (c ApiUser) uploadImage() (ok bool, msg, url string) {
var fileUrlPath = ""
ok = false
file, handel, err := c.Request.FormFile("file")
if err != nil {
var data []byte
c.Params.Bind(&data, "file")
handel := c.Params.Files["file"][0]
if data == nil || len(data) == 0 {
return
}
defer file.Close()
// file, handel, err := c.Request.FormFile("file")
// if err != nil {
// return
// }
// defer file.Close()
// 生成上传路径
fileUrlPath = "public/upload/" + c.getUserId() + "/images/logo"
dir := revel.BasePath + "/" + fileUrlPath
err = os.MkdirAll(dir, 0755)
err := os.MkdirAll(dir, 0755)
if err != nil {
return
}
@ -129,11 +136,11 @@ func (c ApiUser) uploadImage() (ok bool, msg, url string) {
}
filename = NewGuid() + ext
data, err := ioutil.ReadAll(file)
if err != nil {
LogJ(err)
return
}
// data, err := ioutil.ReadAll(file)
// if err != nil {
// LogJ(err)
// return
// }
// > 5M?
if len(data) > 5*1024*1024 {