Add comprehensive upload/download debugging to fix file storage issues
This commit is contained in:
@@ -1247,9 +1247,11 @@ func createUserFileHandler(w http.ResponseWriter, r *http.Request, db *database.
|
|||||||
storedPath = "/" + storedPath
|
storedPath = "/" + storedPath
|
||||||
}
|
}
|
||||||
written := int64(len(data))
|
written := int64(len(data))
|
||||||
|
fmt.Printf("[DEBUG] Upload: user=%s, file=%s, size=%d, path=%s\n", userID.String(), header.Filename, len(data), storedPath)
|
||||||
if storageClient != nil {
|
if storageClient != nil {
|
||||||
rel := strings.TrimPrefix(storedPath, "/")
|
rel := strings.TrimPrefix(storedPath, "/")
|
||||||
remotePath := path.Join("/users", userID.String(), rel)
|
remotePath := path.Join("/users", userID.String(), rel)
|
||||||
|
fmt.Printf("[DEBUG] Uploading to WebDAV: %s\n", remotePath)
|
||||||
if err = storageClient.Upload(r.Context(), remotePath, bytes.NewReader(data), int64(len(data))); err != nil {
|
if err = storageClient.Upload(r.Context(), remotePath, bytes.NewReader(data), int64(len(data))); err != nil {
|
||||||
errors.LogError(r, err, "WebDAV upload failed, falling back to local disk")
|
errors.LogError(r, err, "WebDAV upload failed, falling back to local disk")
|
||||||
} else {
|
} else {
|
||||||
@@ -1273,19 +1275,24 @@ func createUserFileHandler(w http.ResponseWriter, r *http.Request, db *database.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fallback: write to temp directory (WebDAV should be the primary storage)
|
// Fallback: write to temp directory (WebDAV should be the primary storage)
|
||||||
|
fmt.Printf("[DEBUG] WebDAV is nil or failed, using local storage fallback\n")
|
||||||
baseDir := filepath.Join("/tmp", "uploads", "users", userID.String())
|
baseDir := filepath.Join("/tmp", "uploads", "users", userID.String())
|
||||||
targetDir := filepath.Join(baseDir, parentPath)
|
targetDir := filepath.Join(baseDir, parentPath)
|
||||||
|
fmt.Printf("[DEBUG] Creating directory: %s\n", targetDir)
|
||||||
if err = os.MkdirAll(targetDir, 0o755); err != nil {
|
if err = os.MkdirAll(targetDir, 0o755); err != nil {
|
||||||
errors.LogError(r, err, "Failed to create target dir in /tmp")
|
errors.LogError(r, err, "Failed to create target dir in /tmp")
|
||||||
errors.WriteError(w, errors.CodeInternal, "Server error", http.StatusInternalServerError)
|
errors.WriteError(w, errors.CodeInternal, "Server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
outPath := filepath.Join(targetDir, header.Filename)
|
outPath := filepath.Join(targetDir, header.Filename)
|
||||||
|
fmt.Printf("[DEBUG] Writing file to: %s\n", outPath)
|
||||||
if err = os.WriteFile(outPath, data, 0o644); err != nil {
|
if err = os.WriteFile(outPath, data, 0o644); err != nil {
|
||||||
|
fmt.Printf("[DEBUG] Failed to write file: %v\n", err)
|
||||||
errors.LogError(r, err, "Failed to write file to /tmp")
|
errors.LogError(r, err, "Failed to write file to /tmp")
|
||||||
errors.WriteError(w, errors.CodeInternal, "Server error", http.StatusInternalServerError)
|
errors.WriteError(w, errors.CodeInternal, "Server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
fmt.Printf("[DEBUG] File written successfully to local storage: %s\n", outPath)
|
||||||
|
|
||||||
f, err = db.CreateFile(r.Context(), nil, &userID, header.Filename, storedPath, "file", written)
|
f, err = db.CreateFile(r.Context(), nil, &userID, header.Filename, storedPath, "file", written)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user