webtest1s commited on
Commit
19ec90f
·
verified ·
1 Parent(s): 71724d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -20,29 +20,35 @@ def list_files():
20
 
21
 
22
  def upload_file(file):
 
 
23
  responses = {}
24
 
 
 
25
  # Try writing to /data
26
  try:
27
- path_data = f"/data/{file.name}"
28
- with open(path_data, "wb") as f:
29
- f.write(file.read())
 
30
  responses["/data"] = f"Uploaded to {path_data}"
31
  except Exception as e:
32
  responses["/data"] = f"Failed: {str(e)}"
33
 
34
  # Try writing to /1
35
  try:
36
- path_1 = f"/1/{file.name}"
37
- with open(path_1, "wb") as f:
38
- f.write(file.read())
 
 
39
  responses["/1"] = f"Uploaded to {path_1}"
40
  except Exception as e:
41
  responses["/1"] = f"Failed: {str(e)}"
42
 
43
  return responses
44
 
45
-
46
  with gr.Blocks() as app:
47
  gr.Markdown("## 📂 Storage Debugger")
48
 
 
20
 
21
 
22
  def upload_file(file):
23
+ import os
24
+
25
  responses = {}
26
 
27
+ filename = os.path.basename(file.name) # ✅ FIX
28
+
29
  # Try writing to /data
30
  try:
31
+ path_data = f"/data/{filename}"
32
+ with open(file.name, "rb") as src:
33
+ with open(path_data, "wb") as dst:
34
+ dst.write(src.read())
35
  responses["/data"] = f"Uploaded to {path_data}"
36
  except Exception as e:
37
  responses["/data"] = f"Failed: {str(e)}"
38
 
39
  # Try writing to /1
40
  try:
41
+ os.makedirs("/1", exist_ok=True) # ensure folder exists
42
+ path_1 = f"/1/{filename}"
43
+ with open(file.name, "rb") as src:
44
+ with open(path_1, "wb") as dst:
45
+ dst.write(src.read())
46
  responses["/1"] = f"Uploaded to {path_1}"
47
  except Exception as e:
48
  responses["/1"] = f"Failed: {str(e)}"
49
 
50
  return responses
51
 
 
52
  with gr.Blocks() as app:
53
  gr.Markdown("## 📂 Storage Debugger")
54