1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 10:18:38 +00:00

Web editor: support upload files

This commit is contained in:
Unknwon
2016-08-30 05:07:50 -07:00
parent 7c31f235da
commit 643142acab
24 changed files with 503 additions and 600 deletions

View File

@@ -1685,11 +1685,12 @@ func NewAttachment(name string, buf []byte, file multipart.File) (_ *Attachment,
Name: name,
}
if err = os.MkdirAll(path.Dir(attach.LocalPath()), os.ModePerm); err != nil {
localPath := attach.LocalPath()
if err = os.MkdirAll(path.Dir(localPath), os.ModePerm); err != nil {
return nil, fmt.Errorf("MkdirAll: %v", err)
}
fw, err := os.Create(attach.LocalPath())
fw, err := os.Create(localPath)
if err != nil {
return nil, fmt.Errorf("Create: %v", err)
}
@@ -1701,17 +1702,11 @@ func NewAttachment(name string, buf []byte, file multipart.File) (_ *Attachment,
return nil, fmt.Errorf("Copy: %v", err)
}
sess := x.NewSession()
defer sessionRelease(sess)
if err := sess.Begin(); err != nil {
if _, err := x.Insert(attach); err != nil {
return nil, err
}
if _, err := sess.Insert(attach); err != nil {
return nil, err
}
return attach, sess.Commit()
return attach, nil
}
func getAttachmentByUUID(e Engine, uuid string) (*Attachment, error) {