Spaces:
Sleeping
Sleeping
Commit
·
0c43391
1
Parent(s):
ad443b1
update: supabase storage upload code
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import os
|
2 |
import tempfile
|
3 |
import time
|
@@ -25,23 +26,41 @@ os.environ['MOVIEPY_TEMP_DIR'] = '/tmp/moviepy'
|
|
25 |
|
26 |
def upload_to_supabase(video_path, bucket_name="JewelmirrorVideoGeneration"):
|
27 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
with open(video_path, 'rb') as f:
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
public_url = supabase.storage.from_(bucket_name).get_public_url(file_name)
|
|
|
|
|
|
|
|
|
|
|
33 |
return public_url
|
|
|
34 |
except Exception as e:
|
35 |
print(f"Error uploading to Supabase: {str(e)}")
|
36 |
return None
|
37 |
|
38 |
|
39 |
def download_image(url):
|
40 |
-
"""
|
41 |
-
Download an image from the web and save it as a temporary file.
|
42 |
-
:param url: URL of the image.
|
43 |
-
:return: Path to the temporary file.
|
44 |
-
"""
|
45 |
try:
|
46 |
response = requests.get(url, stream=True)
|
47 |
response.raise_for_status()
|
|
|
1 |
+
import mimetypes
|
2 |
import os
|
3 |
import tempfile
|
4 |
import time
|
|
|
26 |
|
27 |
def upload_to_supabase(video_path, bucket_name="JewelmirrorVideoGeneration"):
|
28 |
try:
|
29 |
+
if not os.path.exists(video_path):
|
30 |
+
raise FileNotFoundError(f"Video file not found: {video_path}")
|
31 |
+
|
32 |
+
content_type = mimetypes.guess_type(video_path)[0] or 'video/mp4'
|
33 |
+
file_name = os.path.basename(video_path)
|
34 |
+
|
35 |
+
options = {
|
36 |
+
"content-type": content_type,
|
37 |
+
"x-upsert": "true",
|
38 |
+
"cache-control": "max-age=3600"
|
39 |
+
}
|
40 |
+
|
41 |
with open(video_path, 'rb') as f:
|
42 |
+
file_data = f.read()
|
43 |
+
|
44 |
+
supabase.storage.from_(bucket_name).upload(
|
45 |
+
path=file_name,
|
46 |
+
file=file_data,
|
47 |
+
file_options=options
|
48 |
+
)
|
49 |
|
50 |
public_url = supabase.storage.from_(bucket_name).get_public_url(file_name)
|
51 |
+
|
52 |
+
response = requests.head(public_url)
|
53 |
+
if response.status_code != 200:
|
54 |
+
raise Exception(f"Upload verification failed: {response.status_code}")
|
55 |
+
|
56 |
return public_url
|
57 |
+
|
58 |
except Exception as e:
|
59 |
print(f"Error uploading to Supabase: {str(e)}")
|
60 |
return None
|
61 |
|
62 |
|
63 |
def download_image(url):
|
|
|
|
|
|
|
|
|
|
|
64 |
try:
|
65 |
response = requests.get(url, stream=True)
|
66 |
response.raise_for_status()
|