|
@@ -429,15 +429,27 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- //Generate an UUID for this upload
|
|
|
|
- uploadUUID := uuid.NewV4().String()
|
|
|
|
- uploadFolder := filepath.Join(*tmp_directory, "uploads", uploadUUID)
|
|
|
|
- os.MkdirAll(uploadFolder, 0700)
|
|
|
|
|
|
+ //Check if it is huge file upload mode
|
|
|
|
+ isHugeFile := false
|
|
|
|
+ hugefile, _ := common.Mv(r, "hugefile", false)
|
|
|
|
+ if hugefile == "true" {
|
|
|
|
+ isHugeFile = true
|
|
|
|
+ }
|
|
|
|
+
|
|
targetUploadLocation := filepath.Join(realUploadPath, filename)
|
|
targetUploadLocation := filepath.Join(realUploadPath, filename)
|
|
if !fs.FileExists(realUploadPath) {
|
|
if !fs.FileExists(realUploadPath) {
|
|
os.MkdirAll(realUploadPath, 0755)
|
|
os.MkdirAll(realUploadPath, 0755)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //Generate an UUID for this upload
|
|
|
|
+ uploadUUID := uuid.NewV4().String()
|
|
|
|
+ uploadFolder := filepath.Join(*tmp_directory, "uploads", uploadUUID)
|
|
|
|
+ if isHugeFile {
|
|
|
|
+ //Upload to the same directory as the target location.
|
|
|
|
+ uploadFolder = filepath.Join(realUploadPath, ".metadata/.upload", uploadUUID)
|
|
|
|
+ }
|
|
|
|
+ os.MkdirAll(uploadFolder, 0700)
|
|
|
|
+
|
|
//Start websocket connection
|
|
//Start websocket connection
|
|
var upgrader = websocket.Upgrader{}
|
|
var upgrader = websocket.Upgrader{}
|
|
upgrader.CheckOrigin = func(r *http.Request) bool { return true }
|
|
upgrader.CheckOrigin = func(r *http.Request) bool { return true }
|
|
@@ -501,7 +513,22 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
|
|
//File block. Save it to tmp folder
|
|
//File block. Save it to tmp folder
|
|
chunkFilepath := filepath.Join(uploadFolder, "upld_"+strconv.Itoa(blockCounter))
|
|
chunkFilepath := filepath.Join(uploadFolder, "upld_"+strconv.Itoa(blockCounter))
|
|
chunkName = append(chunkName, chunkFilepath)
|
|
chunkName = append(chunkName, chunkFilepath)
|
|
- ioutil.WriteFile(chunkFilepath, message, 0700)
|
|
|
|
|
|
+ writeErr := ioutil.WriteFile(chunkFilepath, message, 0700)
|
|
|
|
+
|
|
|
|
+ if writeErr != nil {
|
|
|
|
+ //Unable to write block. Is the tmp folder fulled?
|
|
|
|
+ log.Println("[Upload] Upload chunk write failed: " + err.Error())
|
|
|
|
+ c.WriteMessage(1, []byte(`{\"error\":\"Write file chunk to disk failed\"}`))
|
|
|
|
+
|
|
|
|
+ //Close the connection
|
|
|
|
+ c.WriteControl(8, []byte{}, time.Now().Add(time.Second))
|
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
|
+ c.Close()
|
|
|
|
+
|
|
|
|
+ //Clear the tmp files
|
|
|
|
+ os.RemoveAll(uploadFolder)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
//Update the last upload chunk time
|
|
//Update the last upload chunk time
|
|
lastChunkArrivalTime = time.Now().Unix()
|
|
lastChunkArrivalTime = time.Now().Unix()
|
|
@@ -510,7 +537,7 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
|
|
totalFileSize += fs.GetFileSize(chunkFilepath)
|
|
totalFileSize += fs.GetFileSize(chunkFilepath)
|
|
if totalFileSize > max_upload_size {
|
|
if totalFileSize > max_upload_size {
|
|
//File too big
|
|
//File too big
|
|
- c.WriteMessage(1, []byte(`{\"error\":\"File size too large.\"}`))
|
|
|
|
|
|
+ c.WriteMessage(1, []byte(`{\"error\":\"File size too large\"}`))
|
|
|
|
|
|
//Close the connection
|
|
//Close the connection
|
|
c.WriteControl(8, []byte{}, time.Now().Add(time.Second))
|
|
c.WriteControl(8, []byte{}, time.Now().Add(time.Second))
|
|
@@ -571,6 +598,9 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
io.Copy(out, srcChunkReader)
|
|
io.Copy(out, srcChunkReader)
|
|
srcChunkReader.Close()
|
|
srcChunkReader.Close()
|
|
|
|
+
|
|
|
|
+ //Delete file immediately to save space
|
|
|
|
+ os.Remove(filesrc)
|
|
}
|
|
}
|
|
|
|
|
|
out.Close()
|
|
out.Close()
|