@@ -765,19 +765,24 @@ func (this *DocumentController) Upload() {
765765
766766 fileName := strconv .FormatInt (time .Now ().UnixNano (), 16 )
767767
768+ tmpPath := fmt .Sprintf ("cache/%v-%v-%v" , bookIdentify , time .Now ().Format ("200601" ), fileName + ext )
769+ err = this .SaveToFile (name , tmpPath )
770+ if err != nil {
771+ beego .Error ("SaveToFile => " , err )
772+ this .JsonResult (6005 , "保存文件失败" )
773+ }
774+
775+ defer func () { os .Remove (tmpPath ) }()
776+
768777 prefix := "uploads"
769778 savePath := filepath .Join ("projects" , bookIdentify , time .Now ().Format ("200601" ), fileName + ext )
770779 if utils .StoreType != utils .StoreOss {
771780 savePath = filepath .Join (prefix , savePath )
781+ os .MkdirAll (filepath .Dir (savePath ), os .ModePerm )
782+ os .Rename (tmpPath , savePath )
772783 }
773- savePath = strings .ReplaceAll (savePath , "\\ " , "/" )
774- os .MkdirAll (filepath .Dir (savePath ), os .ModePerm )
775784
776- err = this .SaveToFile (name , savePath )
777- if err != nil {
778- beego .Error ("SaveToFile => " , err )
779- this .JsonResult (6005 , "保存文件失败" )
780- }
785+ savePath = strings .ReplaceAll (savePath , "\\ " , "/" )
781786
782787 attachment := models .NewAttachment ()
783788 attachment .BookId = bookId
@@ -805,7 +810,7 @@ func (this *DocumentController) Upload() {
805810 }
806811
807812 if utils .StoreType == utils .StoreOss {
808- if err := store .ModelStoreOss .MoveToOss (savePath , savePath , true , false ); err != nil {
813+ if err := store .ModelStoreOss .MoveToOss (tmpPath , savePath , true , false ); err != nil {
809814 beego .Error (err .Error ())
810815 } else {
811816 if fileType == "video" || fileType == "audio" {
0 commit comments